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](swiftlang#400 (comment)]) for more discussion on non-macOS platforms.

Co-authored-by: Pyry Jahkola <pyry.jahkola@iki.fi>
  • Loading branch information
neonichu and pyrtsa committed Aug 14, 2023
1 parent b3d8257 commit 3091008
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ 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)
let result = try? url.resourceValues(forKeys: [.isSymbolicLinkKey])
return (result?[.isSymbolicLinkKey] as? Bool) == true
}

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

0 comments on commit 3091008

Please sign in to comment.