mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
[3.13] GH-118447: Fix handling of unreadable symlinks in os.path.realpath()
(GH-118489) (#119163)
(cherry picked from commit caf6064a1b
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
This commit is contained in:
parent
91296146d5
commit
7407267ce4
3 changed files with 32 additions and 13 deletions
|
@ -471,26 +471,26 @@ symbolic links encountered in the path."""
|
|||
if not stat.S_ISLNK(st.st_mode):
|
||||
path = newpath
|
||||
continue
|
||||
if newpath in seen:
|
||||
# Already seen this path
|
||||
path = seen[newpath]
|
||||
if path is not None:
|
||||
# use cached value
|
||||
continue
|
||||
# The symlink is not resolved, so we must have a symlink loop.
|
||||
if strict:
|
||||
# Raise OSError(errno.ELOOP)
|
||||
os.stat(newpath)
|
||||
path = newpath
|
||||
continue
|
||||
target = os.readlink(newpath)
|
||||
except OSError:
|
||||
if strict:
|
||||
raise
|
||||
path = newpath
|
||||
continue
|
||||
# Resolve the symbolic link
|
||||
if newpath in seen:
|
||||
# Already seen this path
|
||||
path = seen[newpath]
|
||||
if path is not None:
|
||||
# use cached value
|
||||
continue
|
||||
# The symlink is not resolved, so we must have a symlink loop.
|
||||
if strict:
|
||||
# Raise OSError(errno.ELOOP)
|
||||
os.stat(newpath)
|
||||
path = newpath
|
||||
continue
|
||||
seen[newpath] = None # not resolved symlink
|
||||
target = os.readlink(newpath)
|
||||
if target.startswith(sep):
|
||||
# Symlink target is absolute; reset resolved path.
|
||||
path = sep
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue