Patchwork [1,of,5] pathauditor: move file system specific check in their own function

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 3, 2015, 10:01 p.m.
Message ID <6b99a8edfcb1ff9faeb9.1449180085@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/11792/
State Accepted
Headers show

Comments

Pierre-Yves David - Dec. 3, 2015, 10:01 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1449174168 28800
#      Thu Dec 03 12:22:48 2015 -0800
# Node ID 6b99a8edfcb1ff9faeb91607408a66586e3b7db7
# Parent  8117e2cd959e49f30a189208b807ad3d622ae312
# EXP-Topic symlink.issue4749
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 6b99a8edfcb1
pathauditor: move file system specific check in their own function

This will make it easy to disable that part when not relevant (eg: auditing
filename for operation in history)

Patch

diff --git a/mercurial/pathutil.py b/mercurial/pathutil.py
--- a/mercurial/pathutil.py
+++ b/mercurial/pathutil.py
@@ -79,38 +79,41 @@  class pathauditor(object):
         while parts:
             prefix = os.sep.join(parts)
             normprefix = os.sep.join(normparts)
             if normprefix in self.auditeddir:
                 break
-            curpath = os.path.join(self.root, prefix)
-            try:
-                st = os.lstat(curpath)
-            except OSError as err:
-                # EINVAL can be raised as invalid path syntax under win32.
-                # They must be ignored for patterns can be checked too.
-                if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
-                    raise
-            else:
-                if stat.S_ISLNK(st.st_mode):
-                    raise error.Abort(
-                        _('path %r traverses symbolic link %r')
-                        % (path, prefix))
-                elif (stat.S_ISDIR(st.st_mode) and
-                      os.path.isdir(os.path.join(curpath, '.hg'))):
-                    if not self.callback or not self.callback(curpath):
-                        raise error.Abort(_("path '%s' is inside nested "
-                                           "repo %r")
-                                         % (path, prefix))
+            self._checkfs(prefix, path)
             prefixes.append(normprefix)
             parts.pop()
             normparts.pop()
 
         self.audited.add(normpath)
         # only add prefixes to the cache after checking everything: we don't
         # want to add "foo/bar/baz" before checking if there's a "foo/.hg"
         self.auditeddir.update(prefixes)
 
+    def _checkfs(self, prefix, path):
+        """raise exception if a file system backed check fails"""
+        curpath = os.path.join(self.root, prefix)
+        try:
+            st = os.lstat(curpath)
+        except OSError as err:
+            # EINVAL can be raised as invalid path syntax under win32.
+            # They must be ignored for patterns can be checked too.
+            if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
+                raise
+        else:
+            if stat.S_ISLNK(st.st_mode):
+                raise error.Abort(
+                    _('path %r traverses symbolic link %r')
+                    % (path, prefix))
+            elif (stat.S_ISDIR(st.st_mode) and
+                  os.path.isdir(os.path.join(curpath, '.hg'))):
+                if not self.callback or not self.callback(curpath):
+                    raise error.Abort(_("path '%s' is inside nested "
+                                        "repo %r") % (path, prefix))
+
     def check(self, path):
         try:
             self(path)
             return True
         except (OSError, error.Abort):