comparison mercurial/pathutil.py @ 49912:bc83ebe07bf0

pathauditor: make _checkfs_exists a static method This fixes the bug detected by pytype where the auditor used in vfs.py may be a no-op auditor (vfs.py, line 398), which doesn't have the _checkfs_exists method.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 12 Jan 2023 16:15:51 +0000
parents 789e152a6bdb
children d718eddf01d9
comparison
equal deleted inserted replaced
49911:c7a04bfabd4d 49912:bc83ebe07bf0
114 # expensive to access). 114 # expensive to access).
115 for prefix in finddirs_rev_noroot(path): 115 for prefix in finddirs_rev_noroot(path):
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:
123 break 125 break
124 126
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:
136 if err.errno == errno.ENOENT: 144 if err.errno == errno.ENOENT:
137 return False 145 return False
147 ) 155 )
148 raise error.Abort(msg) 156 raise error.Abort(msg)
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
156 164
157 def check(self, path): 165 def check(self, path):