Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fleming79 committed Dec 21, 2023
2 parents 30d7f4d + 825e099 commit c8ec7af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,19 @@ def _make_path_posix(path, sep=os.sep):
if path.startswith("\\\\"):
# special case for windows UNC/DFS-style paths, do nothing,
# just flip the slashes around (case below does not work!)
return path.replace("\\", "/")
path = path.replace("\\", "/")
if re.match("[A-Za-z]:", path):
# windows full path like "C:\\local\\path"
return path.lstrip("\\").replace("\\", "/").replace("//", "/")
path = path.lstrip("\\").replace("\\", "/").replace("//", "/")
if path.startswith("\\"):
# windows network path like "\\server\\path"
return "/" + path.lstrip("\\").replace("\\", "/").replace("//", "/")
return path
path = "/" + path.lstrip("\\").replace("\\", "/").replace("//", "/")
if os.name == "nt" and len(path) == 3 and path[1] == ":":
return path # windows root
if remove_trailing_slash:
return path.rstrip("/")
else:
return path


def trailing_sep(path):
Expand Down
3 changes: 2 additions & 1 deletion fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ def test_strip_protocol_expanduser():
assert path != stripped
assert "file://" not in stripped
assert stripped.startswith(os.path.expanduser("~").replace("\\", "/"))
assert not LocalFileSystem._strip_protocol("./").endswith("/")
path = LocalFileSystem._strip_protocol("./", remove_trailing_slash=True)
assert not path.endswith("/")


def test_strip_protocol_no_authority():
Expand Down

0 comments on commit c8ec7af

Please sign in to comment.