Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Undo re-ordering of lstat() and seen lookup
  • Loading branch information
barneygale committed Apr 3, 2024
commit 31955eead612107c8ec350fac8a5f8a03349ffe6
28 changes: 13 additions & 15 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ def realpath(filename, *, strict=False):
if not querying:
path = newpath
continue
try:
st = os.lstat(newpath)
except OSError:
if strict:
raise
is_link = False
else:
is_link = stat.S_ISLNK(st.st_mode)
if not is_link:
path = newpath
continue
# Resolve the symbolic link
if newpath in seen:
# Already seen this path
Expand All @@ -470,24 +481,11 @@ def realpath(filename, *, strict=False):
path = newpath
querying = False
continue
try:
st = os.lstat(newpath)
if not stat.S_ISLNK(st.st_mode):
path = newpath
continue
target = os.readlink(newpath)
except OSError:
if strict:
raise
else:
# Return already resolved part + rest of the path unchanged.
path = newpath
querying = False
continue
seen[newpath] = None # not resolved symlink
target = os.readlink(newpath)
if target.startswith(sep):
# Symlink target is absolute; reset resolved path.
path = sep
seen[newpath] = None # not resolved symlink
# Push the symlink path onto the stack, and signal its specialness by
# also pushing None. When these entries are popped, we'll record the
# fully-resolved symlink target in the 'seen' mapping.
Expand Down