Skip to content

Commit

Permalink
use mv when in and out are local (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 authored Sep 9, 2024
1 parent 1a374be commit 77610a3
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions cacholote/extra_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
return cast(F, wrapper)


def _filesystem_is_local(fs: fsspec.AbstractFileSystem) -> bool:
return isinstance(fs, fsspec.get_filesystem_class("file"))


def _kwargs_to_str(**kwargs: Any) -> str:
return " ".join([f"{k}={v}" for k, v in kwargs.items()])

Expand Down Expand Up @@ -235,7 +231,7 @@ def decode_xr_object(
if file_json["type"] == "application/vnd+zarr":
filename_or_obj = fs.get_mapper(urlpath)
else:
if _filesystem_is_local(fs):
if "file" in fs.protocol:
filename_or_obj = urlpath
else:
# Download local copy
Expand Down Expand Up @@ -302,7 +298,7 @@ def _store_xr_object(
raise ValueError(f"type {filetype!r} is NOT supported.")

_store_file_object(
fs if _filesystem_is_local(fs) else fsspec.filesystem("file"),
fs if "file" in fs.protocol else fsspec.filesystem("file"),
tmpfilename,
fs,
urlpath,
Expand Down Expand Up @@ -362,10 +358,10 @@ def _store_file_object(
urlpath=fs_out.unstrip_protocol(urlpath_out),
size=fs_in.size(urlpath_in),
):
if fs_in == fs_out:
if fs_in == fs_out or ("file" in fs_in.protocol and "file" in fs_out.protocol):
func = fs_in.mv if io_delete_original else fs_in.cp
func(urlpath_in, urlpath_out, **kwargs)
elif _filesystem_is_local(fs_in):
elif "file" in fs_in.protocol:
fs_out.put(urlpath_in, urlpath_out, **kwargs)
else:
with fs_in.open(urlpath_in, "rb") as f_in:
Expand Down

0 comments on commit 77610a3

Please sign in to comment.