Skip to content

Commit

Permalink
Use URL.resourceValues() for symlink detection
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
neonichu and pyrtsa committed Aug 15, 2023
1 parent b3d8257 commit 06d5f76
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,10 @@ private struct LocalFileSystem: FileSystem {
}

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

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

0 comments on commit 06d5f76

Please sign in to comment.