Issue 1682940: os.walk should traverse outward symlinks (original) (raw)

To my dismay, I discovered that os.walk will ignore all symlinks, even symlinks that link to somewhere outside of the directory being walked. So I made a little patch to os.py, I hope you apply it, or some figment thereof.

The detection of "outward" symlinks is unreliable because there may be a link there which links "back" into the walked hierarchy. For 2.6, os.walk already has a "followlinks" keyword argument, which will follow all symlinks. You can easily restrict them by removing them from the "dirs" list yielded to the caller.

Closing as outdated. IMO, the one thing that could be improved is to have a cache of visited directories, and to not visit one if it's in the cache.