-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize localfs.info Reduces no. of stat calls and avoids _strip_protocol call which is slow when we have large no. of files. For reducing stat calls upstream, I have a PR in fsspec/filesystem_spec#1659.
- Loading branch information
Showing
5 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from os import readlink, stat | ||
from stat import S_ISDIR, S_ISLNK, S_ISREG | ||
from typing import Any | ||
|
||
|
||
def _localfs_info(path: str) -> dict[str, Any]: | ||
out = stat(path, follow_symlinks=False) | ||
if link := S_ISLNK(out.st_mode): | ||
out = stat(path, follow_symlinks=True) | ||
if S_ISDIR(out.st_mode): | ||
t = "directory" | ||
elif S_ISREG(out.st_mode): | ||
t = "file" | ||
else: | ||
t = "other" | ||
|
||
result = { | ||
"name": path, | ||
"size": out.st_size, | ||
"type": t, | ||
"created": out.st_ctime, | ||
"islink": link, | ||
"mode": out.st_mode, | ||
"uid": out.st_uid, | ||
"gid": out.st_gid, | ||
"mtime": out.st_mtime, | ||
"ino": out.st_ino, | ||
"nlink": out.st_nlink, | ||
} | ||
if link: | ||
result["destination"] = readlink(path) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters