fspath: introduce relparts

This commit is contained in:
Ruslan Kuprieiev
2021-11-10 20:10:48 +02:00
parent 72066f233b
commit 5214aec1bb
4 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -331,7 +331,7 @@ class BaseFileSystem:
return None
to_infos = (
localfs.path.join(to_info, self.path.relpath(info, from_info))
localfs.path.join(to_info, *self.path.relparts(info, from_info))
for info in from_infos
)
callback.set_size(len(from_infos))
+3
View File
@@ -77,5 +77,8 @@ class Path:
normbase = base.rstrip(self.sep)
return normpath[len(normbase) + 1 :]
def relparts(self, path, base):
return self.parts(self.relpath(path, base))
def as_posix(self, path):
return path.replace(self.sep, posixpath.sep)
+1 -2
View File
@@ -163,8 +163,7 @@ def _build_tree(fs_path, fs, name, **kwargs):
# Yes, this is a BUG, as long as we permit "/" in
# filenames on Windows and "\" on Unix
relpath = fs.path.relpath(file_fs_path, fs_path)
key = tuple(relpath.split(fs.path.sep))
key = fs.path.relparts(file_fs_path, fs_path)
assert key
tree.add(key, meta, obj.hash_info)
+1 -1
View File
@@ -718,7 +718,7 @@ class Output:
fs_path = self.fs.path
if filter_info and filter_info != self.fs_path:
prefix = fs_path.parts(fs_path.relpath(filter_info, self.fs_path))
prefix = fs_path.relparts(filter_info, self.fs_path)
obj = obj.get(self.odb, prefix)
return obj