comparison mercurial/localrepo.py @ 31550:66c3ae6d886c

localrepo: use tryunlink
author Ryan McElroy <rmcelroy@fb.com>
date Tue, 21 Mar 2017 06:50:28 -0700
parents 48b9c9ca09b7
children 7d0459706716
comparison
equal deleted inserted replaced
31549:18b9d9b95719 31550:66c3ae6d886c
2023 # used to avoid circular references so destructors work 2023 # used to avoid circular references so destructors work
2024 def aftertrans(files): 2024 def aftertrans(files):
2025 renamefiles = [tuple(t) for t in files] 2025 renamefiles = [tuple(t) for t in files]
2026 def a(): 2026 def a():
2027 for vfs, src, dest in renamefiles: 2027 for vfs, src, dest in renamefiles:
2028 try: 2028 # if src and dest refer to a same file, vfs.rename is a no-op,
2029 # if src and dest refer to a same file, vfs.rename is a no-op, 2029 # leaving both src and dest on disk. delete dest to make sure
2030 # leaving both src and dest on disk. delete dest to make sure 2030 # the rename couldn't be such a no-op.
2031 # the rename couldn't be such a no-op. 2031 vfs.tryunlink(dest)
2032 vfs.unlink(dest)
2033 except OSError as ex:
2034 if ex.errno != errno.ENOENT:
2035 raise
2036 try: 2032 try:
2037 vfs.rename(src, dest) 2033 vfs.rename(src, dest)
2038 except OSError: # journal file does not yet exist 2034 except OSError: # journal file does not yet exist
2039 pass 2035 pass
2040 return a 2036 return a