Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion fsspec/implementations/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,9 @@ def discard(self):
os.remove(self.fn)

def commit(self):
self.fs.put(self.fn, self.path, **self.kwargs)
# calling put() with list arguments avoids path expansion and additional operations
# like isdir()
self.fs.put([self.fn], [self.path], **self.kwargs)
# we do not delete the local copy, it's still in the cache.

@property
Expand Down
16 changes: 16 additions & 0 deletions fsspec/implementations/tests/test_cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,3 +1342,19 @@ def test_filecache_write(tmpdir, m):
def test_cache_protocol_is_preserved():
fs = fsspec.filesystem("filecache", target_protocol="file")
assert fs.protocol == "filecache"


@pytest.mark.parametrize("protocol", ["simplecache", "filecache"])
def test_local_temp_file_put_by_list2(protocol, mocker, tmp_path) -> None:
fs = fsspec.filesystem(protocol, target_protocol="memory")

spy_put = mocker.spy(fs.fs, "put")
spy_isdir = mocker.spy(fs.fs, "isdir")

with fs.open("memory://some/file.txt", mode="wb") as file:
file.write(b"hello")

# passed by list
spy_put.assert_called_once_with([file.name], ["/some/file.txt"])
# which avoids isdir() check
spy_isdir.assert_not_called()
2 changes: 1 addition & 1 deletion fsspec/tests/test_caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,4 @@ def test_cache_kwargs(mocker):
# We don't care about the first parameter, just retrieve its expected value.
# It is a random location that cannot be predicted.
# The important thing is the 'overwrite' kwarg
fs.fs.put.assert_called_with(fs.fs.put.call_args[0][0], "/test", overwrite=True)
fs.fs.put.assert_called_with(fs.fs.put.call_args[0][0], ["/test"], overwrite=True)
Loading