Index: posixpath.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/posixpath.py,v retrieving revision 1.65 diff -C2 -r1.65 posixpath.py *** posixpath.py 12 May 2004 03:51:39 -0000 1.65 --- posixpath.py 5 Jun 2004 18:56:47 -0000 *************** *** 405,416 **** for i in range(2, len(bits)+1): component = join(*bits[0:i]) ! if islink(component): ! resolved = os.readlink(component) ! (dir, file) = split(component) ! resolved = normpath(join(dir, resolved)) ! newpath = join(*([resolved] + bits[i:])) ! return realpath(newpath) return filename supports_unicode_filenames = False --- 405,438 ---- for i in range(2, len(bits)+1): component = join(*bits[0:i]) ! # Resolve symbolic links. ! if islink(component): ! resolved = _resolve_link(component) ! if resolved is None: ! # Infinite loop -- return original component + rest of the path ! return join(*([component] + bits[i:])) ! else: ! newpath = join(*([resolved] + bits[i:])) ! return realpath(newpath) return filename + + def _resolve_link (path): + """Internal helper function. Takes a path and follows symlinks + until we either arrive at something that isn't a symlink, or + encounter a path we've seen before (meaning that there's a loop). + """ + paths_seen = [] + while islink(path): + if path in paths_seen: + # Already seen this path, so we must have a symlink loop + return None + paths_seen.append(path) + + # Resolve where the link points to + resolved = os.readlink(path) + (dir, file) = split(path) + path = normpath(join(dir, resolved)) + return path + supports_unicode_filenames = False