Skip to content

Fix: preserve symlinks in ZipArchive compress function #8250

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

Conversation

sphanley
Copy link
Contributor

This PR fixes #8248, by adding the y flag to the zip command that is executed when archiving a package's sources for publication to a registry on a non-Windows OS.

Motivation:

Without this change, packages which contain symlinks in their sources will produce invalid and potentially non-buildable archives when publishing to a registry, since any symlinks are currently transformed into duplicate files during the archive creation, instead of being preserved.

Modifications:

I've added the following flag to the zip call:

-y store symbolic links as the link instead of the referenced file

I've additionally modified the associated testCompress() test case, adding logic to ensure that symlinks are preserved correctly.

Result:

With this change, the resulting zipfile that is uploaded to a registry will contain symlinks consistent with the original package sources.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov added bug registry SwiftPM Registry-related changes test suite improvements to SwiftPM test suite labels Jan 27, 2025
@sphanley
Copy link
Contributor Author

Thanks for the review, @MaxDesiatov! Apologies for the failing test on Linux, I'll try to dig into what's going on there and make sure this works cross-platform.

@sphanley
Copy link
Contributor Author

@MaxDesiatov, I believe I've got this working– there's an issue that seems specific to Ubuntu 20.04 when the symlink in the unit test is at the root of the test's temp directory, but moving it to a subdirectory seems to behave correctly across MacOS and Linux and provides the same coverage for the functionality.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@sphanley
Copy link
Contributor Author

sphanley commented Feb 5, 2025

I hate to be a bother, but any chance someone can re-invoke the tests? Looks like the Windows job never reported its status, but I believe the tests should have passed.

@jakepetroules
Copy link
Contributor

@swift-ci test Windows

@dschaefer2
Copy link
Member

Thanks!

@dschaefer2 dschaefer2 merged commit 2215d09 into swiftlang:main Feb 6, 2025
5 checks passed
bripeticca pushed a commit to bripeticca/swift-package-manager that referenced this pull request Feb 28, 2025
This PR fixes swiftlang#8248, by adding the `y` flag to the `zip` command that is
executed when archiving a package's sources for publication to a
registry on a non-Windows OS.

### Motivation:

Without this change, packages which contain symlinks in their sources
will produce invalid and potentially non-buildable archives when
publishing to a registry, since any symlinks are currently transformed
into duplicate files during the archive creation, instead of being
preserved.

### Modifications:

I've added the following flag to the `zip` call:
>   -y   store symbolic links as the link instead of the referenced file

I've additionally modified the associated `testCompress()` test case,
adding logic to ensure that symlinks are preserved correctly.

### Result:

With this change, the resulting zipfile that is uploaded to a registry
will contain symlinks consistent with the original package sources.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug registry SwiftPM Registry-related changes test suite improvements to SwiftPM test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swift package-registry publish incorrectly handles packages containing symlinks
4 participants