equal
deleted
inserted
replaced
229 else: |
229 else: |
230 checkdir = path |
230 checkdir = path |
231 cachedir = None |
231 cachedir = None |
232 name = tempfile.mktemp(dir=checkdir, prefix='checklink-') |
232 name = tempfile.mktemp(dir=checkdir, prefix='checklink-') |
233 try: |
233 try: |
234 fd = tempfile.NamedTemporaryFile(dir=checkdir, |
234 fd = None |
235 prefix='hg-checklink-') |
235 if cachedir is None: |
|
236 fd = tempfile.NamedTemporaryFile(dir=checkdir, |
|
237 prefix='hg-checklink-') |
|
238 target = os.path.basename(fd.name) |
|
239 else: |
|
240 # create a fixed file to link to; doesn't matter if it |
|
241 # already exists. |
|
242 target = 'checklink-target' |
|
243 open(os.path.join(cachedir, target), 'w').close() |
236 try: |
244 try: |
237 os.symlink(os.path.basename(fd.name), name) |
245 os.symlink(target, name) |
238 if cachedir is None: |
246 if cachedir is None: |
239 os.unlink(name) |
247 os.unlink(name) |
240 else: |
248 else: |
241 try: |
249 try: |
242 os.rename(name, checklink) |
250 os.rename(name, checklink) |
247 # link creation might race, try again |
255 # link creation might race, try again |
248 if inst[0] == errno.EEXIST: |
256 if inst[0] == errno.EEXIST: |
249 continue |
257 continue |
250 raise |
258 raise |
251 finally: |
259 finally: |
252 fd.close() |
260 if fd is not None: |
|
261 fd.close() |
253 except AttributeError: |
262 except AttributeError: |
254 return False |
263 return False |
255 except OSError as inst: |
264 except OSError as inst: |
256 # sshfs might report failure while successfully creating the link |
265 # sshfs might report failure while successfully creating the link |
257 if inst[0] == errno.EIO and os.path.exists(name): |
266 if inst[0] == errno.EIO and os.path.exists(name): |