Commit 411bf641 authored by Victor Stinner's avatar Victor Stinner

Issue #23605: os.walk() doesn't need to call entry.is_symlink() if followlinks

is True
parent 91427733
...@@ -374,7 +374,10 @@ def walk(top, topdown=True, onerror=None, followlinks=False): ...@@ -374,7 +374,10 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
if is_dir: if is_dir:
dirs.append(entry.name) dirs.append(entry.name)
else:
nondirs.append(entry.name)
if is_dir and not followlinks:
try: try:
if entry.is_symlink(): if entry.is_symlink():
symlinks.add(entry.name) symlinks.add(entry.name)
...@@ -383,8 +386,6 @@ def walk(top, topdown=True, onerror=None, followlinks=False): ...@@ -383,8 +386,6 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# entry is not a symbolik link, same behaviour than # entry is not a symbolik link, same behaviour than
# os.path.islink(). # os.path.islink().
pass pass
else:
nondirs.append(entry.name)
except OSError as error: except OSError as error:
# scandir() or iterating into scandir() iterator raised an OSError # scandir() or iterating into scandir() iterator raised an OSError
if onerror is not None: if onerror is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment