[PATCH 1 of 2] vfs: add the possibility to have a "ward" to check vfs usage

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Aug 11 10:52:24 UTC 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1470323266 -7200
#      Thu Aug 04 17:07:46 2016 +0200
# Node ID b84b218971cfb131023b7e9550cb112e6195841b
# Parent  46d9a5bb2fb0a3629328995948f9ddb0ef0ca4a5
# EXP-Topic vfs.ward
vfs: add the possibility to have a "ward" to check vfs usage

The function will be called anytime we open a file. The first usage of this
'ward' will be to check that lock are properly taken before accessing file.
Later we might use it to ensure we use the right vfs to access files, allowing
more vfs to be introduced.

We currently only apply the ward on 'open' operation. We will extend this to
other operations like copy, creation and removal later. The current readonlyvfs
seems to have the same shortcoming.

diff -r 46d9a5bb2fb0 -r b84b218971cf mercurial/scmutil.py
--- a/mercurial/scmutil.py	Mon Aug 08 18:05:10 2016 +0200
+++ b/mercurial/scmutil.py	Thu Aug 04 17:07:46 2016 +0200
@@ -482,7 +482,8 @@ class vfs(abstractvfs):
     This class is used to hide the details of COW semantics and
     remote file access from higher level code.
     '''
-    def __init__(self, base, audit=True, expandpath=False, realpath=False):
+    def __init__(self, base, audit=True, expandpath=False, realpath=False,
+                 ward=None):
         if expandpath:
             base = util.expandpath(base)
         if realpath:
@@ -491,6 +492,11 @@ class vfs(abstractvfs):
         self.mustaudit = audit
         self.createmode = None
         self._trustnlink = None
+        # optional function to validate operation on file
+        # intended to be user for developer checks.
+        #
+        # XXX should be call for other things than 'open'
+        self._ward = ward
 
     @property
     def mustaudit(self):
@@ -583,6 +589,8 @@ class vfs(abstractvfs):
                         self._trustnlink = nlink > 1 or util.checknlink(f)
                     if nlink > 1 or not self._trustnlink:
                         util.rename(util.mktempcopy(f), f)
+        if self._ward is not None:
+            self._ward(f, mode)
         fp = util.posixfile(f, mode)
         if nlink == 0:
             self._fixfilemode(f)


More information about the Mercurial-devel mailing list