Skip to content

Commit 8be9763

Browse files
authored
Fix write mode for filecache (#1622)
1 parent 54ce0b4 commit 8be9763

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

fsspec/implementations/cached.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,8 @@ def cat(
651651
def _open(self, path, mode="rb", **kwargs):
652652
path = self._strip_protocol(path)
653653
if "r" not in mode:
654-
fn = self._make_local_details(path)
654+
hash = self._mapper(path)
655+
fn = os.path.join(self.storage[-1], hash)
655656
user_specified_kwargs = {
656657
k: v
657658
for k, v in kwargs.items()

fsspec/implementations/tests/test_cached.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,3 +1313,17 @@ def patched_put(*args, **kwargs):
13131313
assert m.cat("myfile") == b"1"
13141314
assert m.cat("otherfile") == b"2"
13151315
assert called[0] == 1 # copy was done in one go
1316+
1317+
1318+
def test_filecache_write(tmpdir, m):
1319+
fs = fsspec.filesystem(
1320+
"filecache", target_protocol="memory", cache_storage=str(tmpdir)
1321+
)
1322+
fn = "sample_file_in_mem.txt"
1323+
data = "hello world from memory"
1324+
with fs.open(fn, "w") as f:
1325+
assert not m.exists(fn)
1326+
f.write(data)
1327+
1328+
assert m.cat(fn) == data.encode()
1329+
assert fs.cat(fn) == data.encode()

0 commit comments

Comments
 (0)