File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -984,7 +984,9 @@ def discard(self):
984984 os .remove (self .fn )
985985
986986 def commit (self ):
987- self .fs .put (self .fn , self .path , ** self .kwargs )
987+ # calling put() with list arguments avoids path expansion and additional operations
988+ # like isdir()
989+ self .fs .put ([self .fn ], [self .path ], ** self .kwargs )
988990 # we do not delete the local copy, it's still in the cache.
989991
990992 @property
Original file line number Diff line number Diff line change @@ -1342,3 +1342,19 @@ def test_filecache_write(tmpdir, m):
13421342def test_cache_protocol_is_preserved ():
13431343 fs = fsspec .filesystem ("filecache" , target_protocol = "file" )
13441344 assert fs .protocol == "filecache"
1345+
1346+
1347+ @pytest .mark .parametrize ("protocol" , ["simplecache" , "filecache" ])
1348+ def test_local_temp_file_put_by_list2 (protocol , mocker , tmp_path ) -> None :
1349+ fs = fsspec .filesystem (protocol , target_protocol = "memory" )
1350+
1351+ spy_put = mocker .spy (fs .fs , "put" )
1352+ spy_isdir = mocker .spy (fs .fs , "isdir" )
1353+
1354+ with fs .open ("memory://some/file.txt" , mode = "wb" ) as file :
1355+ file .write (b"hello" )
1356+
1357+ # passed by list
1358+ spy_put .assert_called_once_with ([file .name ], ["/some/file.txt" ])
1359+ # which avoids isdir() check
1360+ spy_isdir .assert_not_called ()
Original file line number Diff line number Diff line change @@ -289,4 +289,4 @@ def test_cache_kwargs(mocker):
289289 # We don't care about the first parameter, just retrieve its expected value.
290290 # It is a random location that cannot be predicted.
291291 # The important thing is the 'overwrite' kwarg
292- fs .fs .put .assert_called_with (fs .fs .put .call_args [0 ][0 ], "/test" , overwrite = True )
292+ fs .fs .put .assert_called_with (fs .fs .put .call_args [0 ][0 ], [ "/test" ] , overwrite = True )
You can’t perform that action at this time.
0 commit comments