[Python-ideas] BetterWalk, a better and faster os.walk() for Python
Random832
random832 at fastmail.us
Fri Nov 23 04:06:05 CET 2012
Some thoughts:
I'm suspicious of your use of Windows' built-in pattern matching. There
are a number of quirks to it you haven't accounted for... for example:
it matches short filenames, the behavior you noted of "?" at the end of
patterns also applies to the end of the 'filename portion' (e.g.
foo?.txt can match foo.txt), and the behavior of patterns ending in ".*"
or "." isn't like fnmatch.
your find_data_to_stat function ignores the symlink flag, and so will
indicate that a symlink is either a normal file or a directory. This is
desirable for internal use within walk _only if_ followlinks=True.
Meanwhile, the linux function will simply result in DT_LNK, which means
this should really be called iterdir_lstat.
To get the benefit of windows' directory flag, and to define the minimum
required for os.walk(...,followlinks=True), maybe the API should be an
iterdir_lstat with a specific option to request "isdir", which will
populate st_mode with S_IFDIR either from the win32 find data or by, on
linux, calling stat on anything that comes back with DT_LNK, and when it
is false will always populate st_mode with S_IFLNK in the case of
symbolic links.
More information about the Python-ideas
mailing list