Patchwork [05,of,14] vfs: simplify path audit disabling in stream clone

login
register
mail settings
Submitter Pierre-Yves David
Date July 2, 2017, 2:56 a.m.
Message ID <a03c282caf2afbd387ee.1498964190@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21880/
State Accepted
Headers show

Comments

Pierre-Yves David - July 2, 2017, 2:56 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1498955284 -7200
#      Sun Jul 02 02:28:04 2017 +0200
# Node ID a03c282caf2afbd387eebc370b13cf5aa017888e
# Parent  907925f744b8f7886741c4ea278166b58df82f96
# EXP-Topic vfs.ward
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r a03c282caf2a
vfs: simplify path audit disabling in stream clone

The whole 'mustaudit' API is quite complex compared to its actual usage by its
unique user in stream clone.

Instead we add a "auditpath" parameter to 'vfs.__call_'. The stream clone code
then explicitly open files with path auditing disabled.

The 'mustaudit' API will be cleaned up in the next changeset.

Patch

diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -225,10 +225,11 @@  def generatev1(repo):
                 # partially encode name over the wire for backwards compat
                 yield '%s\0%d\n' % (store.encodedir(name), size)
                 if size <= 65536:
-                    with svfs(name, 'rb') as fp:
+                    with svfs(name, 'rb', auditpath=False) as fp:
                         yield fp.read(size)
                 else:
-                    for chunk in util.filechunkiter(svfs(name), limit=size):
+                    data = svfs(name, auditpath=False)
+                    for chunk in util.filechunkiter(data, limit=size):
                         yield chunk
         finally:
             svfs.mustaudit = oldaudit
diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -320,7 +320,8 @@  class vfs(abstractvfs):
         os.chmod(name, self.createmode & 0o666)
 
     def __call__(self, path, mode="r", text=False, atomictemp=False,
-                 notindexed=False, backgroundclose=False, checkambig=False):
+                 notindexed=False, backgroundclose=False, checkambig=False,
+                 auditpath=True):
         '''Open ``path`` file, which is relative to vfs root.
 
         Newly created directories are marked as "not to be indexed by
@@ -344,11 +345,12 @@  class vfs(abstractvfs):
         only for writing), and is useful only if target file is
         guarded by any lock (e.g. repo.lock or repo.wlock).
         '''
-        if self._audit:
-            r = util.checkosfilename(path)
-            if r:
-                raise error.Abort("%s: %r" % (r, path))
-        self.audit(path)
+        if auditpath:
+            if self._audit:
+                r = util.checkosfilename(path)
+                if r:
+                    raise error.Abort("%s: %r" % (r, path))
+            self.audit(path)
         f = self.join(path)
 
         if not text and "b" not in mode: