Skip to content

fix(fsspec): don't silently skip get_file for file:// and Windows paths - #831

Open
andyhetianjun wants to merge 1 commit into
developmentseed:mainfrom
andyhetianjun:fix/fsspec-get-file-local-url
Open

andyhetianjun wants to merge 1 commit into
developmentseed:mainfrom
andyhetianjun:fix/fsspec-get-file-local-url

Conversation

@andyhetianjun

Copy link
Copy Markdown

Closes #830

_get_file returned early, without writing anything or raising, whenever urlparse(lpath) found a scheme. That meant get_file(rpath, "file:///tmp/out.txt") did nothing, and on Windows every normal path did nothing too, since urlparse reads C: as the scheme c.

This PR uses fsspec's split_protocol instead. It doesn't treat a drive letter as a protocol, so Windows paths go through unchanged. A file:// prefix is stripped, and any other protocol (like s3://...) now raises a ValueError instead of returning silently. The directory check after it is the same as before.

Tests: I added three tests to tests/test_fsspec.py that use the memory store, so they don't need MinIO:

  • get_file to a file:// URL writes the bytes
  • get_file to C:\Users\me\out.txt passes that path on to the local store's _pipe_file (mocked, since CI runs on Linux)
  • get_file to s3://bucket/out.txt raises ValueError

All three fail on main and pass with this change. I don't have a Rust toolchain set up, so I tested this change to fsspec.py against the published 0.12.1 wheel, with fsspec 2026.2.0 and pytest 9.0.2 from uv.lock. Docker isn't running on my machine, so the MinIO tests didn't run here. None of them call get or get_file. The rest of test_fsspec.py gave the same results with and without this change. The only failure, test_construct_local_store_fsync, fails on main too because the 0.12.1 wheel doesn't have fsync yet. ruff check, ruff format and pyright 1.1.406 are clean on the two files.

I only have a Mac, so I couldn't try a real Windows path end to end. #763 may still cause problems for local paths on Windows after this point.

#818 changes the same if line in _get_file, so whichever one merges second will have a small conflict. I'm happy to rebase.

… paths

`_get_file` returned without writing anything when `lpath` had a URL
scheme. That includes `file://` URLs, and every Windows path, since
`urlparse("C:\\...")` reads the drive letter as a scheme.

Use fsspec's `split_protocol`, which ignores drive letters, strip a
`file://` prefix, and raise a `ValueError` for any other protocol.

This branch has not been deployed

No deployments
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.

fsspec: get_file silently writes nothing for file:// and Windows paths

1 participant