##// END OF EJS Templates
pathauditor: make _checkfs_exists a static method...
Arseniy Alekseyev -
r50807:bc83ebe0 default
parent child Browse files
Show More
@@ -116,7 +116,9 b' class pathauditor:'
116 if prefix in self.auditeddir:
116 if prefix in self.auditeddir:
117 res = self.auditeddir[prefix]
117 res = self.auditeddir[prefix]
118 else:
118 else:
119 res = self._checkfs_exists(prefix, path)
119 res = pathauditor._checkfs_exists(
120 self.root, prefix, path, self.callback
121 )
120 if self._cached:
122 if self._cached:
121 self.auditeddir[prefix] = res
123 self.auditeddir[prefix] = res
122 if not res:
124 if not res:
@@ -125,11 +127,17 b' class pathauditor:'
125 if self._cached:
127 if self._cached:
126 self.audited.add(path)
128 self.audited.add(path)
127
129
128 def _checkfs_exists(self, prefix: bytes, path: bytes) -> bool:
130 @staticmethod
131 def _checkfs_exists(
132 root,
133 prefix: bytes,
134 path: bytes,
135 callback: Optional[Callable[[bytes], bool]] = None,
136 ):
129 """raise exception if a file system backed check fails.
137 """raise exception if a file system backed check fails.
130
138
131 Return a bool that indicates that the directory (or file) exists."""
139 Return a bool that indicates that the directory (or file) exists."""
132 curpath = os.path.join(self.root, prefix)
140 curpath = os.path.join(root, prefix)
133 try:
141 try:
134 st = os.lstat(curpath)
142 st = os.lstat(curpath)
135 except OSError as err:
143 except OSError as err:
@@ -149,7 +157,7 b' class pathauditor:'
149 elif stat.S_ISDIR(st.st_mode) and os.path.isdir(
157 elif stat.S_ISDIR(st.st_mode) and os.path.isdir(
150 os.path.join(curpath, b'.hg')
158 os.path.join(curpath, b'.hg')
151 ):
159 ):
152 if not self.callback or not self.callback(curpath):
160 if not callback or not callback(curpath):
153 msg = _(b"path '%s' is inside nested repo %r")
161 msg = _(b"path '%s' is inside nested repo %r")
154 raise error.Abort(msg % (path, pycompat.bytestr(prefix)))
162 raise error.Abort(msg % (path, pycompat.bytestr(prefix)))
155 return True
163 return True
@@ -427,13 +427,19 b' class vfs(abstractvfs):'
427 ) -> bool:
427 ) -> bool:
428 """return True if the path is a regular file or a symlink and
428 """return True if the path is a regular file or a symlink and
429 the directories along the path are "normal", that is
429 the directories along the path are "normal", that is
430 not symlinks or nested hg repositories."""
430 not symlinks or nested hg repositories.
431
432 Ignores the `_audit` setting, and checks the directories regardless.
433 `dircache` is used to cache the directory checks.
434 """
431 try:
435 try:
432 for prefix in pathutil.finddirs_rev_noroot(util.localpath(path)):
436 for prefix in pathutil.finddirs_rev_noroot(util.localpath(path)):
433 if prefix in dircache:
437 if prefix in dircache:
434 res = dircache[prefix]
438 res = dircache[prefix]
435 else:
439 else:
436 res = self.audit._checkfs_exists(prefix, path)
440 res = pathutil.pathauditor._checkfs_exists(
441 self.base, prefix, path
442 )
437 dircache[prefix] = res
443 dircache[prefix] = res
438 if not res:
444 if not res:
439 return False
445 return False
General Comments 0
You need to be logged in to leave comments. Login now