mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
GH-117546: Fix symlink resolution in os.path.realpath('loop/../link')
(#117568)
Continue resolving symlink targets after encountering a symlink loop, which matches coreutils `realpath` behaviour.
This commit is contained in:
parent
6bc0b33a91
commit
630df37116
4 changed files with 7 additions and 17 deletions
|
@ -431,11 +431,6 @@ symbolic links encountered in the path."""
|
|||
# the same links.
|
||||
seen = {}
|
||||
|
||||
# Whether we're calling lstat() and readlink() to resolve symlinks. If we
|
||||
# encounter an OSError for a symlink loop in non-strict mode, this is
|
||||
# switched off.
|
||||
querying = True
|
||||
|
||||
while rest:
|
||||
name = rest.pop()
|
||||
if name is None:
|
||||
|
@ -453,9 +448,6 @@ symbolic links encountered in the path."""
|
|||
newpath = path + name
|
||||
else:
|
||||
newpath = path + sep + name
|
||||
if not querying:
|
||||
path = newpath
|
||||
continue
|
||||
try:
|
||||
st = os.lstat(newpath)
|
||||
if not stat.S_ISLNK(st.st_mode):
|
||||
|
@ -477,11 +469,8 @@ symbolic links encountered in the path."""
|
|||
if strict:
|
||||
# Raise OSError(errno.ELOOP)
|
||||
os.stat(newpath)
|
||||
else:
|
||||
# Return already resolved part + rest of the path unchanged.
|
||||
path = newpath
|
||||
querying = False
|
||||
continue
|
||||
path = newpath
|
||||
continue
|
||||
seen[newpath] = None # not resolved symlink
|
||||
target = os.readlink(newpath)
|
||||
if target.startswith(sep):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue