[PATCH 05 of 14] util: use tryunlink in unlinkpath

Ryan McElroy rm at fb.com
Mon Mar 20 22:10:48 EDT 2017


# HG changeset patch
# User Ryan McElroy <rmcelroy at fb.com>
# Date 1490059858 25200
#      Mon Mar 20 18:30:58 2017 -0700
# Node ID 2908e421fa11b827f880de73cfa53667cc0635cb
# Parent  6c9e676047b5dc2469cd9c00ca82e9389a287839
util: use tryunlink in unlinkpath

We just introduced a func to attempt a file removal. Start using it.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1606,11 +1606,10 @@ class atomictempfile(object):
 
 def unlinkpath(f, ignoremissing=False):
     """unlink and remove the directory if it is empty"""
-    try:
+    if ignoremissing:
+        tryunlink(f)
+    else:
         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))


More information about the Mercurial-devel mailing list