Fix registry download with symlinks in root #9411
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix registry download with symlinks in the root
Motivation:
You can find the reproducer here: https://github.com/fortmarek/symlink-swiftpm-reproducer/tree/main
When running the following:
rm -rf ~/.swiftpm .build && swift package purge-cacheswift package --replace-scm-with-registry resolveThe resolution fails with:
This is because this particular version of the library has the following files in the root directory:
AGENT.mdCLAUDE.mdsymlink pointing toAGENT.mdThe error occurs here when moving the downloaded source as part of the stripFirstLevel method where files are moved one-by-one. But when
AGENT.mdis returned as the first file from thegetDirectoryContents, the subsequent move ofCLAUDE.mdfails because themovemethod ofFileSystemchecks whether a file exists – but in the case of symlinks, it follows them, and since theCLAUDE.mdsymlink points toAGENT.mdthat was already moved, the method throws an error.Modifications:
The fix is in the
swift-tools-support-corelibrary by changing theexistsmethod to not follow symlinks: swiftlang/swift-tools-support-core#530Note this PR will be invalid until that PR is merged.
Result:
Following the repro steps from the motivation results in a successful SwiftPM resolution.