From afa2113acfb337c019dc2ef7acab2bb9a68c69b4 Mon Sep 17 00:00:00 2001 From: Martin Durant Date: Sat, 22 Jun 2024 21:07:36 -0400 Subject: [PATCH] Three fixes (#1633) * Three fixes * fix the fix --- fsspec/generic.py | 3 +++ fsspec/implementations/cached.py | 5 +++-- fsspec/implementations/http.py | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fsspec/generic.py b/fsspec/generic.py index 5e1412cb2..9bad0f048 100644 --- a/fsspec/generic.py +++ b/fsspec/generic.py @@ -197,6 +197,7 @@ async def _find(self, path, maxdepth=None, withdirs=False, detail=False, **kwarg ) result = {} for k, v in out.items(): + v = v.copy() # don't corrupt target FS dircache name = fs.unstrip_protocol(k) v["name"] = name result[name] = v @@ -210,6 +211,7 @@ async def _info(self, url, **kwargs): out = await fs._info(url, **kwargs) else: out = fs.info(url, **kwargs) + out = out.copy() # don't edit originals out["name"] = fs.unstrip_protocol(out["name"]) return out @@ -224,6 +226,7 @@ async def _ls( out = await fs._ls(url, detail=True, **kwargs) else: out = fs.ls(url, detail=True, **kwargs) + out = [o.copy() for o in out] # don't edit originals for o in out: o["name"] = fs.unstrip_protocol(o["name"]) if detail: diff --git a/fsspec/implementations/cached.py b/fsspec/implementations/cached.py index 707e684a0..447e4f267 100644 --- a/fsspec/implementations/cached.py +++ b/fsspec/implementations/cached.py @@ -795,7 +795,8 @@ def info(self, path, **kwargs): if self._intrans: f = [_ for _ in self.transaction.files if _.path == path] if f: - return {"name": path, "size": f[0].size or f[0].tell(), "type": "file"} + size = os.path.getsize(f[0].fn) if f[0].closed else f[0].tell() + return {"name": path, "size": size, "type": "file"} f = any(_.path.startswith(path + "/") for _ in self.transaction.files) if f: return {"name": path, "size": 0, "type": "directory"} @@ -901,7 +902,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.close() def close(self): - self.size = self.fh.tell() + # self.size = self.fh.tell() if self.closed: return self.fh.close() diff --git a/fsspec/implementations/http.py b/fsspec/implementations/http.py index 4580764ce..c9ab177eb 100644 --- a/fsspec/implementations/http.py +++ b/fsspec/implementations/http.py @@ -560,6 +560,7 @@ def __init__( if mode != "rb": raise NotImplementedError("File mode not supported") self.asynchronous = asynchronous + self.loop = loop self.url = url self.session = session self.details = {"name": url, "size": size, "type": "file"} @@ -572,7 +573,6 @@ def __init__( cache_options=cache_options, **kwargs, ) - self.loop = loop def read(self, length=-1): """Read bytes from file @@ -736,6 +736,7 @@ async def cor(): return r self.r = sync(self.loop, cor) + self.loop = fs.loop def seek(self, loc, whence=0): if loc == 0 and whence == 1: