Skip to content

Commit

Permalink
Three fixes (#1633)
Browse files Browse the repository at this point in the history
* Three fixes

* fix the fix
  • Loading branch information
martindurant authored Jun 23, 2024
1 parent 527728d commit afa2113
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions fsspec/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions fsspec/implementations/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion fsspec/implementations/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -572,7 +573,6 @@ def __init__(
cache_options=cache_options,
**kwargs,
)
self.loop = loop

def read(self, length=-1):
"""Read bytes from file
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit afa2113

Please sign in to comment.