Skip to content

Conversation

@fortmarek
Copy link
Contributor

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-cache
  • followed with swift package --replace-scm-with-registry resolve

The resolution fails with:

error: 'tuist.Noora': failed downloading tuist.Noora version 0.49.0 source archive from https://tuist.dev/api/registry/swift: failed extracting '/Users/marekfort/Library/Caches/org.swift.swiftpm/registry/downloads/tuist/Noora/0.49.0.zip' to '/Users/marekfort/Library/Caches/org.swift.swiftpm/registry/downloads/tuist/Noora/0.49.0': /Users/marekfort/Library/Caches/org.swift.swiftpm/registry/downloads/tuist/Noora/A76E901C-26CA-4A7B-BAC7-97ABA638F109/CLAUDE.md doesn't exist in file system
error: fatalError

This is because this particular version of the library has the following files in the root directory:

  • AGENT.md
  • CLAUDE.md symlink pointing to AGENT.md

The error occurs here when moving the downloaded source as part of the stripFirstLevel method where files are moved one-by-one. But when AGENT.md is returned as the first file from the getDirectoryContents, the subsequent move of CLAUDE.md fails because the move method of FileSystem checks whether a file exists – but in the case of symlinks, it follows them, and since the CLAUDE.md symlink points to AGENT.md that was already moved, the method throws an error.

Modifications:

The fix is in the swift-tools-support-core library by changing the exists method to not follow symlinks: swiftlang/swift-tools-support-core#530

Note this PR will be invalid until that PR is merged.

Result:

Following the repro steps from the motivation results in a successful SwiftPM resolution.

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