diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2004-08-14 15:01:53 (GMT) |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2004-08-14 15:01:53 (GMT) |
commit | 4ec40648a56b661ca78f795aa0718836b6020e1b (patch) | |
tree | 8721483a04fbf218e56ca7299cd9eb5a9a50f7dc /Lib/posixpath.py | |
parent | f9a098efe1dcfba59d8bf2026892ee65454c29b6 (diff) | |
download | cpython-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.py | 16 |
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 |