comparison mercurial/util.py @ 31539:52361c4f4dac

util: unify unlinkpath Previously, there were two slightly different versions of unlinkpath between windows and posix, but these differences were eliminated in previous patches. Now we can unify these two code paths inside of the util module.
author Ryan McElroy <rmcelroy@fb.com>
date Tue, 21 Mar 2017 06:50:28 -0700
parents 28f00d07e2ee
children 6d5b77abf306
comparison
equal deleted inserted replaced
31538:e6d4cc29fd60 31539:52361c4f4dac
134 statisexec = platform.statisexec 134 statisexec = platform.statisexec
135 statislink = platform.statislink 135 statislink = platform.statislink
136 testpid = platform.testpid 136 testpid = platform.testpid
137 umask = platform.umask 137 umask = platform.umask
138 unlink = platform.unlink 138 unlink = platform.unlink
139 unlinkpath = platform.unlinkpath
140 username = platform.username 139 username = platform.username
141 140
142 # Python compatibility 141 # Python compatibility
143 142
144 _notset = object() 143 _notset = object()
1602 def __exit__(self, exctype, excvalue, traceback): 1601 def __exit__(self, exctype, excvalue, traceback):
1603 if exctype is not None: 1602 if exctype is not None:
1604 self.discard() 1603 self.discard()
1605 else: 1604 else:
1606 self.close() 1605 self.close()
1606
1607 def unlinkpath(f, ignoremissing=False):
1608 """unlink and remove the directory if it is empty"""
1609 try:
1610 unlink(f)
1611 except OSError as e:
1612 if not (ignoremissing and e.errno == errno.ENOENT):
1613 raise
1614 # try removing directories that might now be empty
1615 try:
1616 removedirs(os.path.dirname(f))
1617 except OSError:
1618 pass
1607 1619
1608 def makedirs(name, mode=None, notindexed=False): 1620 def makedirs(name, mode=None, notindexed=False):
1609 """recursive directory creation with parent mode inheritance 1621 """recursive directory creation with parent mode inheritance
1610 1622
1611 Newly created directories are marked as "not to be indexed by 1623 Newly created directories are marked as "not to be indexed by