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

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 .cachedlstat to make clear that we are talking about no-follow stat() here.

Fair point.

On platforms that support fstatat() it should use fstatat(dirfd, name, &buf, ATSYMLINKNOFOLLOW) where dirfd 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 direntry object. I'd like to see dtype and dino, too. dtype should default to DTUNKNOWN, dino 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