Skip to content

Return file:////server/share URIs for UNC paths on Windows - #564

Open
itzzdev09 wants to merge 1 commit into
fsspec:mainfrom
itzzdev09:fix-unc-as-uri
Open

itzzdev09 wants to merge 1 commit into
fsspec:mainfrom
itzzdev09:fix-unc-as-uri

Conversation

@itzzdev09

Copy link
Copy Markdown

Closes #557.

WindowsUPath.as_uri() used pathlib's form for UNC paths, file://server/share/file. fsspec reads the part after file:// as a path, so that URI does not lead back to the share: UPath("file://server/share/file") resolves to <cwd>/server/share/file.

As suggested in the issue, as_uri() now keeps the server in the URI path:

pth = UPath(r"\server\share\file")
pth.as_uri()              # 'file:////server/share/file'
UPath(pth.as_uri()).path  # '//server/share/file'

Drive-letter paths are unchanged (file:///c:/...), and percent-encoding still comes from pathlib.

Tests:

  • Added test_windows_unc_path_as_uri_round_trip to test_core.py (Windows only).
  • The vendored CPython suites (test_pathlib_39312) run PureWindowsPathTest.test_as_uri against WindowsUPath and expect pathlib's file://some/share/ form. I overrode that test in WindowsPathAsPureTest with the file:////some/share/ expectations and a comment explaining the difference. The PureWindowsPath tests themselves are untouched.

Ran on Windows with Python 3.12: test_pathlib_312.py passes, and the new test passes. Both fail without the change. The as_uri tests in test_pathlib_310.py also pass on Python 3.10. black and flake8 are clean.

pathlib writes \server\share\file as file://server/share/file, which
fsspec reads as a relative local path. Return file:////server/share/file
from WindowsUPath.as_uri so the URI round-trips through UPath.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UNC paths are broken when parsing file:// URIs (authority ignored, round-trip fails)

1 participant