Skip to content

TSCBasic: correct resolveSymlink on Windows #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/TSCBasic/PathShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import Foundation
/// Returns the "real path" corresponding to `path` by resolving any symbolic links.
public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
#if os(Windows)
let resolved: String =
(try? FileManager.default.destinationOfSymbolicLink(atPath: path.pathString))
?? path.pathString
var resolved: URL = URL(fileURLWithPath: path.pathString)
if let destination = try? FileManager.default.destinationOfSymbolicLink(atPath: path.pathString) {
resolved = URL(fileURLWithPath: destination, relativeTo: URL(fileURLWithPath: path.pathString))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, could we use AbsolutePath.init(_ str: String, relativeTo basePath: AbsolutePath) here, which takes a string such as what destinationOfSymbolicLink returns (either relative or absolute path) and returns the resulting absolute path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but we want the standardized URL ... so we would need to construct the URL first anyway.

}

return URL(fileURLWithPath: resolved.standardizingPath)
.withUnsafeFileSystemRepresentation {
return resolved.standardized.withUnsafeFileSystemRepresentation {
try! AbsolutePath(validating: String(cString: $0!))
}
#else
Expand Down