brew/Library/Homebrew/cask/reinstall.rb
Mike McQuaid 64311c2889
Add Cask::Installer#prelude to check before download queueing
Fixes #20374

When using HOMEBREW_DOWNLOAD_CONCURRENCY, cask binaries were being
downloaded before checking if the cask could actually be installed
(e.g., disabled casks or conflict checks). This resulted in unnecessary
downloads for casks that would ultimately fail to install.

This change adds a `prelude` method to Cask::Installer that performs
early validation checks (deprecation/disable status and conflicts)
similar to Formula#prelude_fetch. The prelude method is called before
enqueueing downloads in all download queue scenarios (install, reinstall,
and upgrade commands), ensuring that validation failures occur before
the "Fetching downloads for:" message is displayed.

Key changes:
- Add Cask::Installer#prelude method with @ran_prelude tracking
- Call prelude before enqueueing downloads in install/reinstall/upgrade
- Refactor to avoid creating installer objects multiple times
- Maintain backward compatibility for non-download-queue scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-05 14:38:24 +01:00

45 lines
1.3 KiB
Ruby

# typed: strict
# frozen_string_literal: true
module Cask
class Reinstall
sig {
params(
casks: ::Cask::Cask, verbose: T::Boolean, force: T::Boolean, skip_cask_deps: T::Boolean, binaries: T::Boolean,
require_sha: T::Boolean, quarantine: T::Boolean, zap: T::Boolean
).void
}
def self.reinstall_casks(
*casks,
verbose: false,
force: false,
skip_cask_deps: false,
binaries: false,
require_sha: false,
quarantine: false,
zap: false
)
require "cask/installer"
quarantine = true if quarantine.nil?
download_queue = Homebrew::DownloadQueue.new(pour: true) if Homebrew::EnvConfig.download_concurrency > 1
cask_installers = casks.map do |cask|
Installer.new(cask, binaries:, verbose:, force:, skip_cask_deps:, require_sha:, reinstall: true,
quarantine:, zap:, download_queue:)
end
if download_queue
cask_installers.each(&:prelude)
oh1 "Fetching downloads for: #{casks.map { |cask| Formatter.identifier(cask.full_name) }.to_sentence}",
truncate: false
cask_installers.each(&:enqueue_downloads)
download_queue.fetch
end
cask_installers.each(&:install)
end
end
end