[Python-Dev] Issue 11406: adding os.scandir(), a directory iterator returning stat-like info

Nick Coghlan ncoghlan at gmail.com
Sat May 11 18:30:29 CEST 2013


On Sun, May 12, 2013 at 1:42 AM, Christian Heimes <christian at python.org> wrote:
> I suggest that we call it .lstat() and .cached_lstat to make clear that
> we are talking about no-follow stat() here.

Fair point.

> 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.

It may actually make sense to expose the dir_fd as another attribute
of the dir_entry object.

>> 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 dir_entry object.
>
> I'd like to see d_type and d_ino, too. d_type should default to
> DT_UNKNOWN, d_ino to None.

I'd prefer to see a more minimal set to start with - just the features
needed to implement os.walk and os.fwalk more efficiently, and provide
ready access to the full stat result.

Once that core functionality is in place, *then* start debating what
other use cases to optimise based on which platforms would support
those optimisations and which would require dropping back to the full
stat implementation anyway.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list