Patchwork [03,of,11] vfs: add tryunlink method

login
register
mail settings
Submitter Ryan McElroy
Date March 21, 2017, 1:54 p.m.
Message ID <05060c142764cd34c9ad.1490104465@devbig314.prn1.facebook.com>
Download mbox | patch
Permalink /patch/19521/
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 05060c142764cd34c9ad16127bd1b562f9548bd7
# Parent  6652e6d191c677f1188252f1bb4e3e7e88bfcf1c
vfs: add tryunlink method

Thoughout hg code, we see a pattern of attempting to remove a file and then
catching and ignoring any errors due to a missing file in the calling code.
Let's unify this pattern in a single implementation in the vfs layer.

Patch

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -223,6 +223,10 @@  class abstractvfs(object):
     def unlink(self, path=None):
         return util.unlink(self.join(path))
 
+    def tryunlink(self, path=None):
+        """Attempt to remove a file, ignoring missing file errors."""
+        util.tryunlink(self.join(path))
+
     def unlinkpath(self, path=None, ignoremissing=False):
         return util.unlinkpath(self.join(path), ignoremissing=ignoremissing)