changeset 27231:6d29ce250a3d

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)
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 03 Dec 2015 12:22:48 -0800
parents 9f8b8c4e5076
children 79a86a95f325
files mercurial/pathutil.py
diffstat 1 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pathutil.py	Sat Nov 07 16:31:04 2015 +0900
+++ b/mercurial/pathutil.py	Thu Dec 03 12:22:48 2015 -0800
@@ -81,25 +81,7 @@
             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()
@@ -109,6 +91,27 @@
         # 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)