comparison mercurial/util.py @ 12078:e03ca36ba9f3

util: use 'auditor' as consistent name for path auditors
author Martin Geisler <mg@lazybytes.net>
date Sun, 29 Aug 2010 23:56:19 +0200
parents ff6f5310ad92
children 41e56e07eef5
comparison
equal deleted inserted replaced
12077:ff6f5310ad92 12078:e03ca36ba9f3
290 a.pop() 290 a.pop()
291 b.pop() 291 b.pop()
292 b.reverse() 292 b.reverse()
293 return os.sep.join((['..'] * len(a)) + b) or '.' 293 return os.sep.join((['..'] * len(a)) + b) or '.'
294 294
295 def canonpath(root, cwd, myname, audit_path=None): 295 def canonpath(root, cwd, myname, auditor=None):
296 """return the canonical path of myname, given cwd and root""" 296 """return the canonical path of myname, given cwd and root"""
297 if endswithsep(root): 297 if endswithsep(root):
298 rootsep = root 298 rootsep = root
299 else: 299 else:
300 rootsep = root + os.sep 300 rootsep = root + os.sep
301 name = myname 301 name = myname
302 if not os.path.isabs(name): 302 if not os.path.isabs(name):
303 name = os.path.join(root, cwd, name) 303 name = os.path.join(root, cwd, name)
304 name = os.path.normpath(name) 304 name = os.path.normpath(name)
305 if audit_path is None: 305 if auditor is None:
306 audit_path = path_auditor(root) 306 auditor = path_auditor(root)
307 if name != rootsep and name.startswith(rootsep): 307 if name != rootsep and name.startswith(rootsep):
308 name = name[len(rootsep):] 308 name = name[len(rootsep):]
309 audit_path(name) 309 auditor(name)
310 return pconvert(name) 310 return pconvert(name)
311 elif name == root: 311 elif name == root:
312 return '' 312 return ''
313 else: 313 else:
314 # Determine whether `name' is in the hierarchy at or beneath `root', 314 # Determine whether `name' is in the hierarchy at or beneath `root',
328 if not rel: 328 if not rel:
329 # name was actually the same as root (maybe a symlink) 329 # name was actually the same as root (maybe a symlink)
330 return '' 330 return ''
331 rel.reverse() 331 rel.reverse()
332 name = os.path.join(*rel) 332 name = os.path.join(*rel)
333 audit_path(name) 333 auditor(name)
334 return pconvert(name) 334 return pconvert(name)
335 dirname, basename = os.path.split(name) 335 dirname, basename = os.path.split(name)
336 rel.append(basename) 336 rel.append(basename)
337 if dirname == name: 337 if dirname == name:
338 break 338 break
834 remote file access from higher level code. 834 remote file access from higher level code.
835 """ 835 """
836 def __init__(self, base, audit=True): 836 def __init__(self, base, audit=True):
837 self.base = base 837 self.base = base
838 if audit: 838 if audit:
839 self.audit_path = path_auditor(base) 839 self.auditor = path_auditor(base)
840 else: 840 else:
841 self.audit_path = always 841 self.auditor = always
842 self.createmode = None 842 self.createmode = None
843 843
844 @propertycache 844 @propertycache
845 def _can_symlink(self): 845 def _can_symlink(self):
846 return checklink(self.base) 846 return checklink(self.base)
849 if self.createmode is None: 849 if self.createmode is None:
850 return 850 return
851 os.chmod(name, self.createmode & 0666) 851 os.chmod(name, self.createmode & 0666)
852 852
853 def __call__(self, path, mode="r", text=False, atomictemp=False): 853 def __call__(self, path, mode="r", text=False, atomictemp=False):
854 self.audit_path(path) 854 self.auditor(path)
855 f = os.path.join(self.base, path) 855 f = os.path.join(self.base, path)
856 856
857 if not text and "b" not in mode: 857 if not text and "b" not in mode:
858 mode += "b" # for that other OS 858 mode += "b" # for that other OS
859 859
874 if nlink == 0: 874 if nlink == 0:
875 self._fixfilemode(f) 875 self._fixfilemode(f)
876 return fp 876 return fp
877 877
878 def symlink(self, src, dst): 878 def symlink(self, src, dst):
879 self.audit_path(dst) 879 self.auditor(dst)
880 linkname = os.path.join(self.base, dst) 880 linkname = os.path.join(self.base, dst)
881 try: 881 try:
882 os.unlink(linkname) 882 os.unlink(linkname)
883 except OSError: 883 except OSError:
884 pass 884 pass