comparison mercurial/util.py @ 31547:bd9daafbf87c

util: use tryunlink in unlinkpath We just introduced a func to attempt a file removal. Start using it.
author Ryan McElroy <rmcelroy@fb.com>
date Tue, 21 Mar 2017 06:50:28 -0700
parents 6d5b77abf306
children 4ebecf331d7d
comparison
equal deleted inserted replaced
31546:6d5b77abf306 31547:bd9daafbf87c
1604 else: 1604 else:
1605 self.close() 1605 self.close()
1606 1606
1607 def unlinkpath(f, ignoremissing=False): 1607 def unlinkpath(f, ignoremissing=False):
1608 """unlink and remove the directory if it is empty""" 1608 """unlink and remove the directory if it is empty"""
1609 try: 1609 if ignoremissing:
1610 tryunlink(f)
1611 else:
1610 unlink(f) 1612 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 1613 # try removing directories that might now be empty
1615 try: 1614 try:
1616 removedirs(os.path.dirname(f)) 1615 removedirs(os.path.dirname(f))
1617 except OSError: 1616 except OSError:
1618 pass 1617 pass