summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-04-10 17:17:18 (GMT)
committerGitHub <noreply@github.com>2024-04-10 17:17:18 (GMT)
commit630df37116b1c5b381984c547ef9d23792ceb464 (patch)
tree35a80caf614d9ee2d9b2076004ecc2c996b459e1 /Lib/posixpath.py
parent6bc0b33a91713ee62fd1860d28b19cb620c45971 (diff)
downloadcpython-630df37116b1c5b381984c547ef9d23792ceb464.zip
cpython-630df37116b1c5b381984c547ef9d23792ceb464.tar.gz
cpython-630df37116b1c5b381984c547ef9d23792ceb464.tar.bz2
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.
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py15
1 files changed, 2 insertions, 13 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 79e6558..8fd49cd 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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):