Skip to content

Commit cf363a3

Browse files
authored
Merge pull request #140 from compnerd/path-canonicalization
TSCBasic: resolve symbolic links into usable paths
2 parents 31747eb + 20b4203 commit cf363a3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/TSCBasic/PathShims.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ import Foundation
2323
/// Returns the "real path" corresponding to `path` by resolving any symbolic links.
2424
public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
2525
#if os(Windows)
26-
do {
27-
return try AbsolutePath(FileManager.default.destinationOfSymbolicLink(atPath: path.pathString).standardizingPath)
28-
} catch {
29-
return AbsolutePath(path.pathString.standardizingPath)
26+
let resolved: String =
27+
(try? FileManager.default.destinationOfSymbolicLink(atPath: path.pathString))
28+
?? path.pathString
29+
30+
return URL(fileURLWithPath: resolved.standardizingPath)
31+
.withUnsafeFileSystemRepresentation {
32+
try! AbsolutePath(validating: String(cString: $0!))
3033
}
3134
#else
3235
let pathStr = path.pathString

0 commit comments

Comments
 (0)