Skip to content

Commit 77610a3

Browse files
authored
use mv when in and out are local (#132)
1 parent 1a374be commit 77610a3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

cacholote/extra_encoders.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
107107
return cast(F, wrapper)
108108

109109

110-
def _filesystem_is_local(fs: fsspec.AbstractFileSystem) -> bool:
111-
return isinstance(fs, fsspec.get_filesystem_class("file"))
112-
113-
114110
def _kwargs_to_str(**kwargs: Any) -> str:
115111
return " ".join([f"{k}={v}" for k, v in kwargs.items()])
116112

@@ -235,7 +231,7 @@ def decode_xr_object(
235231
if file_json["type"] == "application/vnd+zarr":
236232
filename_or_obj = fs.get_mapper(urlpath)
237233
else:
238-
if _filesystem_is_local(fs):
234+
if "file" in fs.protocol:
239235
filename_or_obj = urlpath
240236
else:
241237
# Download local copy
@@ -302,7 +298,7 @@ def _store_xr_object(
302298
raise ValueError(f"type {filetype!r} is NOT supported.")
303299

304300
_store_file_object(
305-
fs if _filesystem_is_local(fs) else fsspec.filesystem("file"),
301+
fs if "file" in fs.protocol else fsspec.filesystem("file"),
306302
tmpfilename,
307303
fs,
308304
urlpath,
@@ -362,10 +358,10 @@ def _store_file_object(
362358
urlpath=fs_out.unstrip_protocol(urlpath_out),
363359
size=fs_in.size(urlpath_in),
364360
):
365-
if fs_in == fs_out:
361+
if fs_in == fs_out or ("file" in fs_in.protocol and "file" in fs_out.protocol):
366362
func = fs_in.mv if io_delete_original else fs_in.cp
367363
func(urlpath_in, urlpath_out, **kwargs)
368-
elif _filesystem_is_local(fs_in):
364+
elif "file" in fs_in.protocol:
369365
fs_out.put(urlpath_in, urlpath_out, **kwargs)
370366
else:
371367
with fs_in.open(urlpath_in, "rb") as f_in:

0 commit comments

Comments
 (0)