Skip to content

Commit

Permalink
localfs: reduce stats calls during info (#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored Aug 12, 2024
1 parent 32ce723 commit 4b79654
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions fsspec/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def info(self, path, **kwargs):
t = "file"
else:
t = "other"

size = out.st_size
if link:
try:
out2 = path.stat(follow_symlinks=True)
size = out2.st_size
except OSError:
size = 0
path = self._strip_protocol(path.path)
else:
# str or path-like
Expand All @@ -87,6 +95,7 @@ def info(self, path, **kwargs):
link = stat.S_ISLNK(out.st_mode)
if link:
out = os.stat(path, follow_symlinks=True)
size = out.st_size
if stat.S_ISDIR(out.st_mode):
t = "directory"
elif stat.S_ISREG(out.st_mode):
Expand All @@ -95,20 +104,15 @@ def info(self, path, **kwargs):
t = "other"
result = {
"name": path,
"size": out.st_size,
"size": size,
"type": t,
"created": out.st_ctime,
"islink": link,
}
for field in ["mode", "uid", "gid", "mtime", "ino", "nlink"]:
result[field] = getattr(out, f"st_{field}")
if result["islink"]:
if link:
result["destination"] = os.readlink(path)
try:
out2 = os.stat(path, follow_symlinks=True)
result["size"] = out2.st_size
except OSError:
result["size"] = 0
return result

def lexists(self, path, **kwargs):
Expand Down

0 comments on commit 4b79654

Please sign in to comment.