comparison mercurial/pathutil.py @ 44195:51c86c6167c1

pathutil: mark parent directories as audited as we go Before 0b7ce0b16d8a (pathauditor: change parts verification order to be root first, 2016-02-11), we used to validate child directories before parents. It was then important to only mark the child audited only after we had audited its parent (ancestors). I'm pretty sure we don't need to do that any more, now that we audit parents before children. Differential Revision: https://phab.mercurial-scm.org/D8002
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 24 Jan 2020 17:25:40 -0800
parents d84420232492
children d52e3826cd4b
comparison
equal deleted inserted replaced
44194:d4c1501225c4 44195:51c86c6167c1
97 normparts = util.splitpath(normpath) 97 normparts = util.splitpath(normpath)
98 assert len(parts) == len(normparts) 98 assert len(parts) == len(normparts)
99 99
100 parts.pop() 100 parts.pop()
101 normparts.pop() 101 normparts.pop()
102 prefixes = []
103 # It's important that we check the path parts starting from the root. 102 # It's important that we check the path parts starting from the root.
104 # This means we won't accidentally traverse a symlink into some other 103 # This means we won't accidentally traverse a symlink into some other
105 # filesystem (which is potentially expensive to access). 104 # filesystem (which is potentially expensive to access).
106 for i in range(len(parts)): 105 for i in range(len(parts)):
107 prefix = pycompat.ossep.join(parts[: i + 1]) 106 prefix = pycompat.ossep.join(parts[: i + 1])
108 normprefix = pycompat.ossep.join(normparts[: i + 1]) 107 normprefix = pycompat.ossep.join(normparts[: i + 1])
109 if normprefix in self.auditeddir: 108 if normprefix in self.auditeddir:
110 continue 109 continue
111 if self._realfs: 110 if self._realfs:
112 self._checkfs(prefix, path) 111 self._checkfs(prefix, path)
113 prefixes.append(normprefix) 112 if self._cached:
113 self.auditeddir.add(normprefix)
114 114
115 if self._cached: 115 if self._cached:
116 self.audited.add(normpath) 116 self.audited.add(normpath)
117 # only add prefixes to the cache after checking everything: we don't
118 # want to add "foo/bar/baz" before checking if there's a "foo/.hg"
119 self.auditeddir.update(prefixes)
120 117
121 def _checkfs(self, prefix, path): 118 def _checkfs(self, prefix, path):
122 """raise exception if a file system backed check fails""" 119 """raise exception if a file system backed check fails"""
123 curpath = os.path.join(self.root, prefix) 120 curpath = os.path.join(self.root, prefix)
124 try: 121 try: