Patchwork [02,of,11] util: use tryunlink in unlinkpath

login
register
mail settings
Submitter Ryan McElroy
Date March 21, 2017, 1:54 p.m.
Message ID <6652e6d191c677f11882.1490104464@devbig314.prn1.facebook.com>
Download mbox | patch
Permalink /patch/19518/
State Accepted
Headers show

Comments

Ryan McElroy - March 21, 2017, 1:54 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1490104228 25200
#      Tue Mar 21 06:50:28 2017 -0700
# Node ID 6652e6d191c677f1188252f1bb4e3e7e88bfcf1c
# Parent  5c9cdd8046845f76e169885ed490a603b911d0d4
util: use tryunlink in unlinkpath

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

Patch

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))