Skip to content

Commit 992d58b

Browse files
committed
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.
1 parent c6d2a20 commit 992d58b

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

Lib/macpath.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,13 @@ def getatime(filename):
122122

123123

124124
def islink(s):
125-
"""Return true if the pathname refers to a symbolic link.
126-
Always false on the Mac, until we understand Aliases.)"""
125+
"""Return true if the pathname refers to a symbolic link."""
127126

128-
return False
127+
try:
128+
import macfs
129+
return macfs.ResolveAliasFile(s)[2]
130+
except:
131+
return False
129132

130133

131134
def isfile(s):
@@ -223,7 +226,7 @@ def walk(top, func, arg):
223226
func(arg, top, names)
224227
for name in names:
225228
name = join(top, name)
226-
if isdir(name):
229+
if isdir(name) and not islink(name):
227230
walk(name, func, arg)
228231

229232

@@ -234,4 +237,17 @@ def abspath(path):
234237
return normpath(path)
235238

236239
# realpath is a no-op on systems without islink support
237-
realpath = abspath
240+
def realpath(path):
241+
path = abspath(path)
242+
try:
243+
import macfs
244+
except ImportError:
245+
return path
246+
if not path:
247+
return path
248+
components = path.split(':')
249+
path = components[0] + ':'
250+
for c in components[1:]:
251+
path = join(path, c)
252+
path = macfs.ResolveAliasFile(path)[0].as_pathname()
253+
return path

0 commit comments

Comments
 (0)