[Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info (original) (raw)
Christian Heimes christian at python.org
Sat May 11 17:42:39 CEST 2013
- Previous message: [Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info
- Next message: [Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Am 11.05.2013 16:34, schrieb Nick Coghlan:
Here's the full set of fields on a current stat object:
statime statimens stblksize stblocks stctime stctimens stdev stgid stino stmode stmtime stmtimens stnlink strdev stsize stuid
And there are more fields on some platforms, e.g. st_birthtime.
To me, that suggests a more reasonable API for os.scandir() might be for it to be an iterator over "direntry" objects:
name (as a string) isfile() isdir() islink() stat() cachedstat (None or a stat object)
I suggest that we call it .lstat() and .cached_lstat to make clear that we are talking about no-follow stat() here. On platforms that support fstatat() it should use fstatat(dir_fd, name, &buf, AT_SYMLINK_NOFOLLOW) where dir_fd is the fd from dirfd() of opendir()'s return value.
On all platforms, the query methods would not require a separate stat() call. On Windows, cachedstat would be populated with a full stat object when scandir builds the entry. On non-Windows platforms, cachedstat would initially be None, and you would have to call stat() to populate it.
+1
If we find other details that we can reliably provide cross-platform from the dir information, then we can add more query methods orst attributes to the direntry object.
I'd like to see d_type and d_ino, too. d_type should default to DT_UNKNOWN, d_ino to None.
Christian
- Previous message: [Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info
- Next message: [Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]