Skip to content

cleanup: preserve metadata during dry runs - #24406

Merged
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
hezhizhen:cleanup-dry-run-metadata
Oct 31, 2026
Merged

MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
hezhizhen:cleanup-dry-run-metadata

Conversation

@hezhizhen

Copy link
Copy Markdown
Contributor

Summary

brew cleanup --dry-run <formula|cask> can delete .DS_Store files and
legacy 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 metadata

Evidence

With an already-installed hello formula in a disposable Homebrew
installation, reproduce the file deletion with:

formula_rack="$(./bin/brew --cellar hello)"
test -d "$formula_rack"
touch "$formula_rack/.DS_Store"
./bin/brew cleanup --dry-run hello
test -f "$formula_rack/.DS_Store"
  • Before: the final check fails because the dry run deletes the file.
    All four new regression examples fail without the guards, covering
    Formula and Cask .DS_Store files, legacy cache files and linkage entries.
  • After: all four examples pass, including with --generic.
    ./bin/brew lgtm --online passes 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.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

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.


- Guard metadata helpers so named-package dry runs preserve files
  and linkage cache entries.
- Cover Formula and Cask metadata through their public cleanup methods.
Copilot AI lite review requested due to automatic review settings October 31, 2026 02:53
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dfc9ec64-ca5a-4afa-89ee-82ffa8b669a9
Commits

Reviewing files that changed from the base of the PR and between fcdfa04 and 276e2ca.

Files selected for processing: 2
  • Library/Homebrew/cleanup.rb
  • Library/Homebrew/test/cleanup_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Dry-run cleanup now leaves cache database files, linkage cache contents and .DS_Store files unchanged for formulas and casks. These files are removed only during a non-dry-run cleanup.

Cleanup helpers now skip cache database and .DS_Store removal during dry runs. Regression tests check that formula and cask cleanup preserve these files, along with selected formula cache files and linkage cache contents.

Changes: Dry-run cleanup

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: Passed 4
Check name Status Explanation
Title check Passed 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 metad…
Description check Passed 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…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

Share

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 31, 2026
Merged via the queue into Homebrew:main with commit ec3c70a Oct 31, 2026
54 checks passed
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.

3 participants

⌂ 换网址