diff --git a/fsspec/implementations/cached.py b/fsspec/implementations/cached.py index 4847c2ef2..74e6a59e4 100644 --- a/fsspec/implementations/cached.py +++ b/fsspec/implementations/cached.py @@ -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 diff --git a/fsspec/implementations/tests/test_cached.py b/fsspec/implementations/tests/test_cached.py index 011f6e50f..513432836 100644 --- a/fsspec/implementations/tests/test_cached.py +++ b/fsspec/implementations/tests/test_cached.py @@ -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() diff --git a/fsspec/tests/test_caches.py b/fsspec/tests/test_caches.py index 5299a0824..ff9d2f97b 100644 --- a/fsspec/tests/test_caches.py +++ b/fsspec/tests/test_caches.py @@ -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)