mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
vfs: add a 'reljoin' function for joining relative paths
The vfs.join method only works for absolute paths. We need something that works for relative paths too when transforming filenames. Since os.path.join may misbehave in tricky encoding situations, encapsulate the new join method in our vfs abstraction. The default implementation remains os.path.join, but this opens the door to other VFSes doing something more intelligent based on their needs. In the same go, we replace the usage of 'os.path.join' in transaction code.
This commit is contained in:
parent
b2cec9668e
commit
329429e77c
@ -261,6 +261,13 @@ class abstractvfs(object):
|
||||
def islink(self, path=None):
|
||||
return os.path.islink(self.join(path))
|
||||
|
||||
def reljoin(self, *paths):
|
||||
"""join various elements of a path together (as os.path.join would do)
|
||||
|
||||
The vfs base is not injected so that path stay relative. This exists
|
||||
to allow handling of strange encoding if needed."""
|
||||
return os.path.join(*paths)
|
||||
|
||||
def lexists(self, path=None):
|
||||
return os.path.lexists(self.join(path))
|
||||
|
||||
|
@ -200,8 +200,8 @@ class transaction(object):
|
||||
return
|
||||
dirname, filename = os.path.split(file)
|
||||
backupfilename = "%s.backup.%s" % (self.journal, filename)
|
||||
backupfile = os.path.join(dirname, backupfilename)
|
||||
vfs = self._vfsmap[location]
|
||||
backupfile = vfs.reljoin(dirname, backupfilename)
|
||||
if vfs.exists(file):
|
||||
filepath = vfs.join(file)
|
||||
backuppath = vfs.join(backupfile)
|
||||
|
Loading…
Reference in New Issue
Block a user