diff --git a/dvc/fs/base.py b/dvc/fs/base.py index b710fdcfb..c54bfc14b 100644 --- a/dvc/fs/base.py +++ b/dvc/fs/base.py @@ -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)) diff --git a/dvc/fs/path.py b/dvc/fs/path.py index 584ec9b73..f06c3b122 100644 --- a/dvc/fs/path.py +++ b/dvc/fs/path.py @@ -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) diff --git a/dvc/objects/stage.py b/dvc/objects/stage.py index b3a88e443..f298cef6e 100644 --- a/dvc/objects/stage.py +++ b/dvc/objects/stage.py @@ -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) diff --git a/dvc/output.py b/dvc/output.py index 6a798e0e3..4abb1c8c4 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -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