# HG changeset patch # User Ryan McElroy # Date 1490104228 25200 # Node ID 52361c4f4dac969251077472c0dfc9561704b32a # Parent e6d4cc29fd602915e374cc4dee52abcb7ac456af 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. diff -r e6d4cc29fd60 -r 52361c4f4dac mercurial/posix.py --- a/mercurial/posix.py Tue Mar 21 06:50:28 2017 -0700 +++ b/mercurial/posix.py Tue Mar 21 06:50:28 2017 -0700 @@ -536,19 +536,6 @@ def makedir(path, notindexed): os.mkdir(path) -def unlinkpath(f, ignoremissing=False): - """unlink and remove the directory if it is empty""" - try: - unlink(f) - except OSError as e: - if not (ignoremissing and e.errno == errno.ENOENT): - raise - # try removing directories that might now be empty - try: - removedirs(os.path.dirname(f)) - except OSError: - pass - def lookupreg(key, name=None, scope=None): return None diff -r e6d4cc29fd60 -r 52361c4f4dac mercurial/util.py --- a/mercurial/util.py Tue Mar 21 06:50:28 2017 -0700 +++ b/mercurial/util.py Tue Mar 21 06:50:28 2017 -0700 @@ -136,7 +136,6 @@ testpid = platform.testpid umask = platform.umask unlink = platform.unlink -unlinkpath = platform.unlinkpath username = platform.username # Python compatibility @@ -1605,6 +1604,19 @@ else: self.close() +def unlinkpath(f, ignoremissing=False): + """unlink and remove the directory if it is empty""" + try: + unlink(f) + except OSError as e: + if not (ignoremissing and e.errno == errno.ENOENT): + raise + # try removing directories that might now be empty + try: + removedirs(os.path.dirname(f)) + except OSError: + pass + def makedirs(name, mode=None, notindexed=False): """recursive directory creation with parent mode inheritance diff -r e6d4cc29fd60 -r 52361c4f4dac mercurial/windows.py --- a/mercurial/windows.py Tue Mar 21 06:50:28 2017 -0700 +++ b/mercurial/windows.py Tue Mar 21 06:50:28 2017 -0700 @@ -385,19 +385,6 @@ break head, tail = os.path.split(head) -def unlinkpath(f, ignoremissing=False): - """unlink and remove the directory if it is empty""" - try: - unlink(f) - except OSError as e: - if not (ignoremissing and e.errno == errno.ENOENT): - raise - # try removing directories that might now be empty - try: - removedirs(os.path.dirname(f)) - except OSError: - pass - def rename(src, dst): '''atomically rename file src to dst, replacing dst if it exists''' try: