Repository navigation
cask: remove pre-staged downloads when installs fail - #24107
Merged
MikeMcQuaid merged 2 commits intoSep 28, 2026
Merged
Conversation
A cask install or upgrade that fails before `Cask::Installer#stage` left its pre-staged copy in `var/homebrew/tmp/.caskroom`, and `brew cleanup` only emptied the formula `.cellar` sibling. Purge the queued copy after the install and upgrade rollbacks and have `brew cleanup` empty both temporary directories.
Contributor
There was a problem hiding this comment.
Copilot review overview
馃煛 Changes recommended
Moderate cleanup and error-preservation issues remain unresolved.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
This pull request cleans up pre-staged cask downloads after failed installs/upgrades and extends brew cleanup to remove interrupted staging data.
Changes:
- Adds
HOMEBREW_TEMP_CASKROOM. - Purges staged downloads during failure handling.
- Adds cleanup behavior and regression tests.
Outstanding moderate findings concern cleanup being skipped when restore/rollback fails, and staging cleanup errors masking the original failure.
| File | Reviewed changes |
|---|---|
Library/鈥婬omebrew/鈥媡est/鈥媠upport/鈥媗ib/鈥媠tartup/鈥媍onfig.rb |
Adds the test caskroom path constant. |
Library/鈥婬omebrew/鈥媡est/鈥媠pec_helper.rb |
Preserves the new constant during tests. |
Library/鈥婬omebrew/鈥媡est/鈥媍leanup_spec.rb |
Tests temporary cask staging cleanup. |
Library/鈥婬omebrew/鈥媡est/鈥媍ask/鈥媢pgrade_spec.rb |
Tests upgrade-failure cleanup. |
Library/鈥婬omebrew/鈥媡est/鈥媍ask/鈥媔nstaller_spec.rb |
Tests install-failure cleanup. |
Library/鈥婬omebrew/鈥媠tartup/鈥媍onfig.rb |
Defines the temporary caskroom path. |
Library/鈥婬omebrew/鈥媍leanup.rb |
Cleans temporary cellar and caskroom contents. |
Library/鈥婬omebrew/鈥媍ask/鈥媢pgrade.rb |
Purges staged downloads during upgrade rollback. |
Library/鈥婬omebrew/鈥媍ask/鈥媔nstaller.rb |
Removes staged downloads after install failures. |
Library/鈥婬omebrew/鈥媍ask/鈥媎ownload.rb |
Uses the new caskroom constant. |
馃挕 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
The purge ran after `restore_backup` and inside the upgrade rollback block, so a failing rollback step skipped it. Run it in an `ensure` after `restore_backup` and after the upgrade rollback block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?I used Claude Code (Claude Opus 5.5) to find the bug, write the patch and tests, and draft this text. I used Codex CLI (GPT-6 Astra) to review the patch. I reviewed the diff and the test results.
Problem
Since #23034, brew extracts each cask to
var/homebrew/tmp/.caskroom/<token>/<version>before it installs it.If the install or upgrade fails before the move into the Caskroom, this copy stays.
brew cleanupdoes not remove it. It only cleanstmp/.cellar.On my Mac,
tmp/.caskroom/chatgpthad 22 old versions (31.4GB).Steps to reproduce
uninstall_preflightblock that raises.brew upgrade --cask <cask>. It fails.brew cleanup.ls $(brew --prefix)/var/homebrew/tmp/.caskroom/<cask>still shows2.0and2.0.staged.Fix
brew cleanupnow also emptiestmp/.caskroom. This covers interrupted runs.HOMEBREW_TEMP_CASKROOMreplaces the path string.Validation
brew lgtmpasses.brew testssuite passes.brew cleanupremoved the 31.4GB.