Skip to content

Commit

Permalink
Fix write mode for filecache (#1622)
Browse files Browse the repository at this point in the history
  • Loading branch information
martindurant authored Jun 6, 2024
1 parent 54ce0b4 commit 8be9763
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fsspec/implementations/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ def cat(
def _open(self, path, mode="rb", **kwargs):
path = self._strip_protocol(path)
if "r" not in mode:
fn = self._make_local_details(path)
hash = self._mapper(path)
fn = os.path.join(self.storage[-1], hash)
user_specified_kwargs = {
k: v
for k, v in kwargs.items()
Expand Down
14 changes: 14 additions & 0 deletions fsspec/implementations/tests/test_cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,17 @@ def patched_put(*args, **kwargs):
assert m.cat("myfile") == b"1"
assert m.cat("otherfile") == b"2"
assert called[0] == 1 # copy was done in one go


def test_filecache_write(tmpdir, m):
fs = fsspec.filesystem(
"filecache", target_protocol="memory", cache_storage=str(tmpdir)
)
fn = "sample_file_in_mem.txt"
data = "hello world from memory"
with fs.open(fn, "w") as f:
assert not m.exists(fn)
f.write(data)

assert m.cat(fn) == data.encode()
assert fs.cat(fn) == data.encode()

0 comments on commit 8be9763

Please sign in to comment.