Repository navigation
cleanup: preserve metadata during dry runs - #24406
Conversation
- Guard metadata helpers so named-package dry runs preserve files and linkage cache entries. - Cover Formula and Cask metadata through their public cleanup methods.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Guard cleanup operations during dry runs Library/Homebrew/cleanup.rb, Library/Homebrew/test/cleanup_spec.rb |
cleanup_cache_db and rm_ds_store now return during dry runs. Tests check that formula cleanup preserves .DS_Store files, cache database files, and linkage cache contents, and that cask cleanup preserves .DS_Store files. |
Merge Risk: 
Minimal · up to 276e2
-
The change correctly preserves cleanup metadata during dry runs without introducing an identified production risk.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title "cleanup: preserve metadata during dry runs" matches the main change. The PR adds dry-run guards to the cache database and .DS_Store cleanup helpers so that named-package dry runs keep metadata files. The title is concise, specific and uses no vague terms.
Full details: Description check
-
Explanation
The description states the problem (named-package brew cleanup --dry-run can delete .DS_Store files, legacy cache databases and prune linkage cache entries), the proposed guard in cleanup_cache_db and rm_ds_store, reproduction steps, before and after test evidence and a risk assessment. It relates directly to the changeset.
-
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the changes include targeted regression coverage for preserving metadata and cache state during dry runs.
No open issues 🎉
What changed in this PR
This pull request fixes brew cleanup --dry-run <formula|cask> so it preserves metadata files, legacy cache databases, and linkage cache entries.
Changes:
- Added dry-run guards to metadata cleanup helpers.
- Added regression coverage for Formula and Cask metadata preservation.
- Preserved existing metadata cleanup behavior outside dry runs.
| File | Description |
|---|---|
Library/Homebrew/test/cleanup_spec.rb |
Verifies that Formula and Cask metadata and cache state remain unchanged during dry runs. |
Library/Homebrew/cleanup.rb |
Prevents metadata deletion and linkage-cache pruning when dry-run mode is enabled. |
Review effort: Lite
Summary
brew cleanup --dry-run <formula|cask>can delete.DS_Storefiles andlegacy cache databases or prune linkage cache entries. Named-package
cleanup calls the metadata helpers without the dry-run guard used by a
full cleanup, violating the documented promise that a dry run removes
nothing.
Add the guard inside both metadata helpers so all callers respect it:
cleanup_cache_db / rm_ds_store + return if dry_run? remove metadataEvidence
With an already-installed
helloformula in a disposable Homebrewinstallation, reproduce the file deletion with:
All four new regression examples fail without the guards, covering
Formula and Cask
.DS_Storefiles, legacy cache files and linkage entries.--generic../bin/brew lgtm --onlinepasses typechecking, style and related tests.Merge Danger
Door: two-way. The change can be reverted without a migration.
Blast Radius: small. The guards only skip metadata removal during dry
runs; regular cleanup continues through the existing paths.
brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?OpenAI Codex assisted with investigation, the patch, regression tests and
this description. The contributor reviewed the code before authorising
submission. Verification included failing and passing runs of the exact
regression examples, a generic-mode run and
./bin/brew lgtm --online.