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

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Oct 9, 2020

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.

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.
@compnerd
Copy link
Member Author

compnerd commented Oct 9, 2020

@swift-ci please test

?? 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.

Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

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

This looks looks good to me, though I think it could be done in a somewhat cleaner way without URL (unless I'm missing something). But that could be a follow-on PR.

@abertelrud
Copy link
Contributor

Also, it would be great to add more testing around this (possibly in separate PR), although I realize that such tests aren't yet running in CI on Windows (I think...?).

@compnerd
Copy link
Member Author

compnerd commented Oct 9, 2020

Yeah, the tests don't work because the tests explicit create file systems in memory using / rather than the \ separator which is required on Windows. Happy to do follow up cleanups to this path though.

@compnerd compnerd merged commit 243beea into swiftlang:main Oct 9, 2020
@compnerd compnerd deleted the resolution branch October 9, 2020 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants