os.walk() with followlinks=False

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

os.walk() with followlinks=False

Nick Coghlan
When discussing http://bugs.python.org/issue13734, Charles-François
noted that when os.walk() is called with "followlinks=False", symlinks
to directories are still included in the "subdirs" list rather than
the "files" list.

This seems rather odd to me, so I'm asking here to see if there's a
specific rationale for it, or if it's just an artifact of the
implementation.

If it's the latter... could we change it for 3.3, or is that too
significant a breach of backwards compatibility?

Even if we can't change os.walk(), does os.walkfd() need to replicate
the annoying behaviour for consistency, or can it instead consider
such symlinks to be files rather than directories?

Cheers,
Nick.

--
Nick Coghlan   |   [hidden email]   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/lists%2B1324100855712-1801473%40n6.nabble.com
Reply | Threaded
Open this post in threaded view
|

Re: os.walk() with followlinks=False

Antoine Pitrou
On Wed, 11 Jan 2012 12:25:46 +1000
Nick Coghlan <[hidden email]> wrote:

> When discussing http://bugs.python.org/issue13734, Charles-François
> noted that when os.walk() is called with "followlinks=False", symlinks
> to directories are still included in the "subdirs" list rather than
> the "files" list.
>
> This seems rather odd to me, so I'm asking here to see if there's a
> specific rationale for it, or if it's just an artifact of the
> implementation.
>
> If it's the latter... could we change it for 3.3, or is that too
> significant a breach of backwards compatibility?

I think we could change it.

> Even if we can't change os.walk(), does os.walkfd() need to replicate
> the annoying behaviour for consistency, or can it instead consider
> such symlinks to be files rather than directories?

IMO walkfd() should do the right thing.

Regards

Antoine.


_______________________________________________
Python-Dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/lists%2B1324100855712-1801473%40n6.nabble.com
Reply | Threaded
Open this post in threaded view
|

Re: os.walk() with followlinks=False

Nick Coghlan
On Thu, Jan 12, 2012 at 12:54 AM, Antoine Pitrou <[hidden email]> wrote:
> On Wed, 11 Jan 2012 12:25:46 +1000
> Nick Coghlan <[hidden email]> wrote:
>> If it's the latter... could we change it for 3.3, or is that too
>> significant a breach of backwards compatibility?
>
> I think we could change it.

For the benefit of those not following the tracker issue,
Charles-François pointed out that putting the symlinks-to-directories
into the files list instead of the subdirectory list isn't really any
better (it just moves the problem to different use cases, such as
those that actually want to read the file contents).

With that being the case, I've changed my mind and figure we may as
well leave the current behaviour alone. I'll think about adding a
filter to walkdir that makes it easy to control the way they're
handled [1].

[1] https://bitbucket.org/ncoghlan/walkdir/issue/9/better-handling-of-dir-symlinks

Cheers,
Nick.

--
Nick Coghlan   |   [hidden email]   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/lists%2B1324100855712-1801473%40n6.nabble.com