Skip to content

Commit d11846f

Browse files
author
Luca Moschella
committed
Refactor the _add_fs_prefix without using os.path.join
1 parent e424bf8 commit d11846f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

fsspec/implementations/prefix.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ def __init__(
2424

2525
self.filesystem = filesystem
2626

27+
def _get_relative_path(self, path: str) -> str:
28+
if path[: len(self.sep)] == self.sep:
29+
return path[len(self.sep) :]
30+
return path
31+
2732
def _add_fs_prefix(self, path: Union[str, Path]) -> Union[str, Sequence[str]]:
2833
if isinstance(path, (str, Path)):
2934
path = stringify_path(path)
3035
protocol, path = split_protocol(path)
31-
path = os.path.join(self.prefix, path)
36+
37+
path = self._get_relative_path(path)
38+
39+
if self.prefix == self.sep:
40+
path = f"{self.sep}{path}" # don't add twice the same sep
41+
else:
42+
path = f"{self.prefix}{self.sep}{path}"
43+
3244
return protocol + "://" + path if protocol is not None else path
3345
elif isinstance(path, Iterable):
3446
return [self._add_fs_prefix(x) for x in path]

0 commit comments

Comments
 (0)