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', |
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 |