Skip to content

Commit c110bd1

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

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: Sources/TSCBasic/FileSystem.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ private struct LocalFileSystem: FileSystem {
383383
}
384384

385385
func isSymlink(_ path: AbsolutePath) -> Bool {
386-
let attrs = try? FileManager.default.attributesOfItem(atPath: path.pathString)
387-
return attrs?[.type] as? FileAttributeType == .typeSymbolicLink
386+
let url = NSURL(fileURLWithPath: path.pathString)
387+
// We are intentionally using `NSURL.resourceValues(forKeys:)` here since it improves performance on Darwin platforms.
388+
let result = try? url.resourceValues(forKeys: [.isSymbolicLinkKey])
389+
return (result?[.isSymbolicLinkKey] as? Bool) == true
388390
}
389391

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

0 commit comments

Comments
 (0)