Skip to content

Commit

Permalink
Use URL.resourceValues() for symlink detection (#428)
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 <pyry.jahkola@iki.fi>
  • Loading branch information
neonichu and pyrtsa authored Aug 15, 2023
1 parent 7963ebc commit c110bd1
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 @@ -383,8 +383,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 c110bd1

Please sign in to comment.