Skip to content

Commit 06d5f76

Browse files
neonichupyrtsa
andcommitted
Use URL.resourceValues() for symlink detection
This should provide a significant performance improvement on macOS. See [this](swiftlang#400 (comment)]) for more discussion on non-macOS platforms. Co-authored-by: Pyry Jahkola <[email protected]>
1 parent b3d8257 commit 06d5f76

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/TSCBasic/FileSystem.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@ private struct LocalFileSystem: FileSystem {
370370
}
371371

372372
func isSymlink(_ path: AbsolutePath) -> Bool {
373-
let attrs = try? FileManager.default.attributesOfItem(atPath: path.pathString)
374-
return attrs?[.type] as? FileAttributeType == .typeSymbolicLink
373+
let url = NSURL(fileURLWithPath: path.pathString)
374+
// We are intentionally using `NSURL.resourceValues(forKeys:)` here since it improves performance on Darwin platforms.
375+
let result = try? url.resourceValues(forKeys: [.isSymbolicLinkKey])
376+
return (result?[.isSymbolicLinkKey] as? Bool) == true
375377
}
376378

377379
func isReadable(_ path: AbsolutePath) -> Bool {

0 commit comments

Comments
 (0)