diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-04-22 13:55:43 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-04-22 13:55:43 (GMT) |
commit | 992d58b770daa61b209fdc3545b5e962acfc735a (patch) | |
tree | c750ee72f56144b1be66f4ae92bffed45e5212af /Lib/macpath.py | |
parent | c6d2a20bc62b1221363c18c6c4f1ba9b4d2b9f8c (diff) | |
download | cpython-992d58b770daa61b209fdc3545b5e962acfc735a.zip cpython-992d58b770daa61b209fdc3545b5e962acfc735a.tar.gz cpython-992d58b770daa61b209fdc3545b5e962acfc735a.tar.bz2 |
Fixes based on ideas from Christopher Smith:
- islink() now returns true for alias files
- walk() no longer follows aliases while traversing
- realpath() implemented, returning an alias-free pathname.
As this could conceivably break existing code I think it isn't a bugfix candidate.
Diffstat (limited to 'Lib/macpath.py')
-rw-r--r-- | Lib/macpath.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py index 91412c5..24f4a14 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -122,10 +122,13 @@ def getatime(filename): def islink(s): - """Return true if the pathname refers to a symbolic link. - Always false on the Mac, until we understand Aliases.)""" + """Return true if the pathname refers to a symbolic link.""" - return False + try: + import macfs + return macfs.ResolveAliasFile(s)[2] + except: + return False def isfile(s): @@ -223,7 +226,7 @@ def walk(top, func, arg): func(arg, top, names) for name in names: name = join(top, name) - if isdir(name): + if isdir(name) and not islink(name): walk(name, func, arg) @@ -234,4 +237,17 @@ def abspath(path): return normpath(path) # realpath is a no-op on systems without islink support -realpath = abspath +def realpath(path): + path = abspath(path) + try: + import macfs + except ImportError: + return path + if not path: + return path + components = path.split(':') + path = components[0] + ':' + for c in components[1:]: + path = join(path, c) + path = macfs.ResolveAliasFile(path)[0].as_pathname() + return path |