summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2004-08-14 15:01:53 (GMT)
committerJohannes Gijsbers <jlg@dds.nl>2004-08-14 15:01:53 (GMT)
commit4ec40648a56b661ca78f795aa0718836b6020e1b (patch)
tree8721483a04fbf218e56ca7299cd9eb5a9a50f7dc /Lib/posixpath.py
parentf9a098efe1dcfba59d8bf2026892ee65454c29b6 (diff)
downloadcpython-4ec40648a56b661ca78f795aa0718836b6020e1b.zip
cpython-4ec40648a56b661ca78f795aa0718836b6020e1b.tar.gz
cpython-4ec40648a56b661ca78f795aa0718836b6020e1b.tar.bz2
bug #990669: os.path.realpath() will resolve symlinks before normalizing the
path, as normalizing the path may alter the meaning of the path if it contains symlinks. Also add tests for infinite symlink loops and parent symlinks that need to be resolved.
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 557f8f2..345a742 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -400,9 +400,11 @@ def abspath(path):
def realpath(filename):
"""Return the canonical path of the specified filename, eliminating any
symbolic links encountered in the path."""
- filename = abspath(filename)
-
- bits = ['/'] + filename.split('/')[1:]
+ if isabs(filename):
+ bits = ['/'] + filename.split('/')[1:]
+ else:
+ bits = filename.split('/')
+
for i in range(2, len(bits)+1):
component = join(*bits[0:i])
# Resolve symbolic links.
@@ -410,13 +412,13 @@ symbolic links encountered in the path."""
resolved = _resolve_link(component)
if resolved is None:
# Infinite loop -- return original component + rest of the path
- return join(*([component] + bits[i:]))
+ return abspath(join(*([component] + bits[i:])))
else:
newpath = join(*([resolved] + bits[i:]))
- return realpath(newpath)
-
- return filename
+ return realpath(newpath)
+ return abspath(filename)
+
def _resolve_link(path):
"""Internal helper function. Takes a path and follows symlinks