[Python-Dev] Updates to PEP 471, the os.scandir() proposal
ethan at stoneleaf.us
Thu Jul 10 02:38:11 CEST 2014
On 07/09/2014 05:15 PM, Victor Stinner wrote:
> 2014-07-09 17:29 GMT+02:00 Ben Hoyt <benhoyt at gmail.com>:
>>> Would this not "break" the tree size script being discussed in the
>>> other thread, as it would follow links and include linked directories
>>> in the "size" of the tree?
> The get_tree_size() function in the PEP would use: "if not
> entry.is_symlink() and entry.is_dir():".
> Note: First I wrote "if entry.is_dir() and not entry.is_symlink():",
> but this syntax is slower on Linux because is_dir() has to call
Wouldn't it only have to call lstat if the entry was, in fact, a link?
> There are only a few cases where you want to handle symlinks
> differently: archive (ex: tar), compute the size of a directory (ex:
> du does not follow symlinks by default, du -L follows them), remove a
I agree with Victor here. If the entry is a link I would want to know if it was a link to a directory or a link to a
file. If I care about not following sym links I can check is_symlink() (or whatever it's called).
More information about the Python-Dev