Argh, I missed --flag v2 on this series. Apologies.

I also split this from the previous three patches because they are actually unrelated cleanups.

On 3/21/17 1:54 PM, Ryan McElroy wrote:
# HG changeset patch
# User Ryan McElroy <rmcel...@fb.com>
# Date 1490104228 25200
#      Tue Mar 21 06:50:28 2017 -0700
# Node ID 5c9cdd8046845f76e169885ed490a603b911d0d4
# Parent  49de4dfb282e2ad4dc91328ffd7fc396ee92b4a0
util: add tryunlink function

Throughout mercurial cdoe, there is a common pattern of attempting to remove
a file and ignoring ENOENT errors. Let's move this into a common function to
allow for cleaner code.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1617,6 +1617,14 @@ def unlinkpath(f, ignoremissing=False):
      except OSError:
          pass
+def tryunlink(f):
+    """Attempt to remove a file, ignoring ENOENT errors."""
+    try:
+        unlink(f)
+    except OSError as e:
+        if e.errno != errno.ENOENT:
+            raise
+
  def makedirs(name, mode=None, notindexed=False):
      """recursive directory creation with parent mode inheritance

_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to