Skip to content

Commit 49ed191

Browse files
committed
TSCBasic: correct resolveSymlink on Windows
This would fail to properly resolve the symbolic links on Windows since the result of the resolution would be a path relative to the location of the original path. However, we would instead treat the path as the absolute path. Correct this which is required to resolve modulemaps inside of directories with symbolic links. This was found by building IndexStoreDB on Windows with SwiftPM.
1 parent 8f9838e commit 49ed191

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Sources/TSCBasic/PathShims.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ 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-
let resolved: String =
27-
(try? FileManager.default.destinationOfSymbolicLink(atPath: path.pathString))
28-
?? path.pathString
26+
var resolved: URL = URL(fileURLWithPath: path.pathString)
27+
if let destination = try? FileManager.default.destinationOfSymbolicLink(atPath: path.pathString) {
28+
resolved = URL(fileURLWithPath: destination, relativeTo: URL(fileURLWithPath: path.pathString))
29+
}
2930

30-
return URL(fileURLWithPath: resolved.standardizingPath)
31-
.withUnsafeFileSystemRepresentation {
31+
return resolved.standardized.withUnsafeFileSystemRepresentation {
3232
try! AbsolutePath(validating: String(cString: $0!))
3333
}
3434
#else

0 commit comments

Comments
 (0)