Skip to content

Fix orphaned fileHashes blocking pack removal#293

Merged
bguidolim merged 1 commit intomainfrom
bruno/fix-orphaned-filehashes-block-pack-removal
Mar 25, 2026
Merged

Fix orphaned fileHashes blocking pack removal#293
bguidolim merged 1 commit intomainfrom
bruno/fix-orphaned-filehashes-block-pack-removal

Conversation

@bguidolim
Copy link
Copy Markdown
Collaborator

Context

mcs sync --global repeatedly tries to remove packs that are already gone, printing:

[WARN] Some artifacts for <pack> could not be removed. Re-run 'mcs sync --global' to retry.

Root cause: unconfigurePack() removes entries from remaining.files after successful file deletion but never cleans up remaining.fileHashes. Since PackArtifactRecord.isEmpty checks fileHashes.isEmpty, orphaned hash entries (present in fileHashes but absent from files) permanently prevent the pack from being fully removed from state.

This data inconsistency was introduced by the conditional copyPackFile namespacing feature (aa7fd9a), which could remove files from files during reconciliation while leaving stale fileHashes behind.

Changes

  • After clearing remaining.files in unconfigurePack(), filter remaining.fileHashes to only keep entries whose key exists in remaining.files — handles both normal removal and orphaned state
  • Added test that seeds a state file with the exact broken pattern (empty files, non-empty fileHashes) and verifies the pack is fully removed

Testing

  • All 876 tests pass
  • New test unconfigureClearsOrphanedFileHashes covers the exact scenario
  • SwiftFormat + SwiftLint clean

- Purge fileHashes entries without corresponding files entries after
  file removal in unconfigurePack(), fixing packs stuck in
  "could not be removed" state on every sync
- Add test seeding orphaned fileHashes to verify full pack removal
@bguidolim bguidolim merged commit 0cf2ccc into main Mar 25, 2026
7 checks passed
@bguidolim bguidolim deleted the bruno/fix-orphaned-filehashes-block-pack-removal branch March 25, 2026 18:10
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.

1 participant