summaryrefslogtreecommitdiff
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorJohannes Gijsbers <jlg@dds.nl>2004-08-14 15:01:53 +0000
committerJohannes Gijsbers <jlg@dds.nl>2004-08-14 15:01:53 +0000
commite990af73e6b4e7a7474148e3ff9740aec9716559 (patch)
treec652644a33bee9eaa74c44591da5d9a29cd00baa /Lib/posixpath.py
parent744f7487d6355f16c6433f88022526ec9146c11a (diff)
downloadcpython-e990af73e6b4e7a7474148e3ff9740aec9716559.tar.gz
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 557f8f21cb..345a74268c 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