Skip to content

Commit 7c3408a

Browse files
lobismartindurant
andauthored
fix: correctly handle local files with colons (:) in name (#1452)
--------- Co-authored-by: Martin Durant <[email protected]>
1 parent 30e479b commit 7c3408a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

fsspec/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def split_protocol(urlpath):
521521
if len(protocol) > 1:
522522
# excludes Windows paths
523523
return protocol, path
524-
if ":" in urlpath and urlpath.find(":") > 1:
524+
if urlpath.startswith("data:"):
525525
return urlpath.split(":", 1)
526526
return None, urlpath
527527

fsspec/generic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,12 @@ async def _pipe_file(
250250
return fs.pipe_file(path, value, **kwargs)
251251

252252
async def _rm(self, url, **kwargs):
253-
fs = _resolve_fs(url, self.method)
253+
urls = url
254+
if isinstance(urls, str):
255+
urls = [urls]
256+
fs = _resolve_fs(urls[0], self.method)
254257
if fs.async_impl:
255-
await fs._rm(url, **kwargs)
258+
await fs._rm(urls, **kwargs)
256259
else:
257260
fs.rm(url, **kwargs)
258261

fsspec/implementations/tests/test_local.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
),
3434
}
3535

36-
3736
csv_files = {
3837
".test.fakedata.1.csv": (b"a,b\n" b"1,2\n"),
3938
".test.fakedata.2.csv": (b"a,b\n" b"3,4\n"),
@@ -56,6 +55,8 @@ def filetexts(d, open=open, mode="t"):
5655
try:
5756
os.chdir(dirname)
5857
for filename, text in d.items():
58+
if dirname := os.path.dirname(filename):
59+
os.makedirs(dirname, exist_ok=True)
5960
f = open(filename, f"w{mode}")
6061
try:
6162
f.write(text)
@@ -991,3 +992,21 @@ def test_cp_two_files(tmpdir):
991992
make_path_posix(os.path.join(target, "file0")),
992993
make_path_posix(os.path.join(target, "file1")),
993994
]
995+
996+
997+
@pytest.mark.skipif(WIN, reason="Windows does not support colons in filenames")
998+
def test_issue_1447():
999+
files_with_colons = {
1000+
".local:file:with:colons.txt": b"content1",
1001+
".colons-after-extension.txt:after": b"content2",
1002+
".colons-after-extension/file:colon.txt:before/after": b"content3",
1003+
}
1004+
with filetexts(files_with_colons, mode="b"):
1005+
for file, contents in files_with_colons.items():
1006+
with fsspec.filesystem("file").open(file, "rb") as f:
1007+
assert f.read() == contents
1008+
1009+
fs, urlpath = fsspec.core.url_to_fs(file)
1010+
assert isinstance(fs, fsspec.implementations.local.LocalFileSystem)
1011+
with fs.open(urlpath, "rb") as f:
1012+
assert f.read() == contents

0 commit comments

Comments
 (0)