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

Augie Fackler raf at durin42.com
Tue Oct 18 09:15:44 EDT 2016


On Fri, Oct 14, 2016 at 03:56:13AM +0200, Pierre-Yves David wrote:
> # 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 678c3cf029eceec20325928cff063ab71ea99761
> # Parent  c0410814002f467c24ef07ce73850ba15b306f8e
> # EXP-Topic vfs.ward
> vfs: add the possibility to have a "ward" to check vfs usage

The word "ward" here is baffling to me. Could it be something like
lockcheckfn or similar that'll be more self-documenting?

>
> 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 --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -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):
> @@ -552,6 +558,9 @@ class vfs(abstractvfs):
>          if not text and "b" not in mode:
>              mode += "b" # for that other OS
>
> +        if self._ward is not None:
> +            self._ward(f, mode, atomictemp)
> +
>          nlink = -1
>          if mode not in ('r', 'rb'):
>              dirname, basename = util.split(f)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list