]> granicus.if.org Git - python/commitdiff
Issue #23605: os.walk() doesn't need to call entry.is_symlink() if followlinks
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 12 Mar 2015 08:12:48 +0000 (09:12 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 12 Mar 2015 08:12:48 +0000 (09:12 +0100)
is True

Lib/os.py

index 8e325e3367e01154ce1c33f6478b1f9de276dc44..a9a57e0bdc50b5b8ede8db241f8bde574423b3fc 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -374,7 +374,10 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
 
             if is_dir:
                 dirs.append(entry.name)
+            else:
+                nondirs.append(entry.name)
 
+            if is_dir and not followlinks:
                 try:
                     if entry.is_symlink():
                         symlinks.add(entry.name)
@@ -383,8 +386,6 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
                     # entry is not a symbolik link, same behaviour than
                     # os.path.islink().
                     pass
-            else:
-                nondirs.append(entry.name)
     except OSError as error:
         # scandir() or iterating into scandir() iterator raised an OSError
         if onerror is not None: