pathauditor: move file system specific check in their own function
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 03 Dec 2015 12:22:48 -0800
changeset 27231 6d29ce250a3d
parent 27230 9f8b8c4e5076
child 27232 79a86a95f325
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)
mercurial/pathutil.py
--- 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)