Skip to content

fix: correctly handle local files with colons (:) in name #1452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fsspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def split_protocol(urlpath):
if len(protocol) > 1:
# excludes Windows paths
return protocol, path
if ":" in urlpath and urlpath.find(":") > 1:
if urlpath.startswith("data:"):
return urlpath.split(":", 1)
return None, urlpath

Expand Down
3 changes: 2 additions & 1 deletion fsspec/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def rsync(
fs.cp(source_files, target_files, **kwargs)
logger.debug(f"{len(to_delete)} files to delete")
if delete_missing:
fs.rm(to_delete)
for file in to_delete:
fs.rm(file)


class GenericFileSystem(AsyncFileSystem):
Expand Down
21 changes: 20 additions & 1 deletion fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
),
}


csv_files = {
".test.fakedata.1.csv": (b"a,b\n" b"1,2\n"),
".test.fakedata.2.csv": (b"a,b\n" b"3,4\n"),
Expand All @@ -56,6 +55,8 @@ def filetexts(d, open=open, mode="t"):
try:
os.chdir(dirname)
for filename, text in d.items():
if dirname := os.path.dirname(filename):
os.makedirs(dirname, exist_ok=True)
f = open(filename, f"w{mode}")
try:
f.write(text)
Expand Down Expand Up @@ -991,3 +992,21 @@ def test_cp_two_files(tmpdir):
make_path_posix(os.path.join(target, "file0")),
make_path_posix(os.path.join(target, "file1")),
]


@pytest.mark.skipif(WIN, reason="Windows does not support colons in filenames")
def test_issue_1447():
files_with_colons = {
".local:file:with:colons.txt": b"content1",
".colons-after-extension.txt:after": b"content2",
".colons-after-extension/file:colon.txt:before/after": b"content3",
}
with filetexts(files_with_colons, mode="b"):
for file, contents in files_with_colons.items():
with fsspec.filesystem("file").open(file, "rb") as f:
assert f.read() == contents

fs, urlpath = fsspec.core.url_to_fs(file)
assert isinstance(fs, fsspec.implementations.local.LocalFileSystem)
with fs.open(urlpath, "rb") as f:
assert f.read() == contents