swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.36k stars 150 forks source link

Windows: symbolic links not created correctly with relative paths #928

Open dschaefer2 opened 1 day ago

dschaefer2 commented 1 day ago

SwiftPM creates a symbolic link in the .build directory to a sibling directory for backwards compatibility reasons. That link is currently in 6.0 not created correctly on Windows.

For Windows we check whether the destPath is a directory to add the SYMBOLIC_LINK_FLAG_DIRECTORY flag when creating the link. However, we don't check whether it's a relative path and just call fileExists to fetch the isDirectory boolean. That assumes the path is relative to the current directory not the symbolic link path.

I notice in corelibs-foundation, the path is resolved correctly before checking if it's a directory:

                let resolvedDest =
                  destPath.isAbsolutePath ? destPath
                                          : joinPath(prefix: path.deletingLastPathComponent,
                                                     suffix: destPath)
dschaefer2 commented 1 day ago

Original SwiftPM issue here: https://github.com/swiftlang/swift-package-manager/issues/7965