Mercurial > public > mercurial-scm > hg
comparison mercurial/posix.py @ 30555:6a672c3b7860
posix: give the cached symlink a real target
The NamedTemporaryFile file is cleared up so checklink ends up as a dangling
symlink, causing cp -r in tests to complain on both Solaris and OS X. Use
a permanent file instead when there is a .hg/cache directory.
author | Martijn Pieters <mjpieters@fb.com> |
---|---|
date | Wed, 30 Nov 2016 16:39:36 +0000 |
parents | 8836f13e3c5b |
children | d623cc6b3742 |
comparison
equal
deleted
inserted
replaced
30554:1775975dd439 | 30555:6a672c3b7860 |
---|---|
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): |