Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cask/reinstall: Support --zap for entirely purging cask files #13116

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion Library/Homebrew/cask/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Install < AbstractCommand
[:switch, "--skip-cask-deps", {
description: "Skip installing cask dependencies.",
}],
[:switch, "--zap", {
description: "For use with `brew reinstall --cask`. Remove all files associated with a cask. " \
"*May remove files which are shared between applications.*",
}],
].freeze

def self.parser(&block)
Expand All @@ -39,6 +43,7 @@ def run
require_sha: args.require_sha?,
quarantine: args.quarantine?,
quiet: args.quiet?,
zap: args.zap?,
)
end

Expand All @@ -50,7 +55,8 @@ def self.install_casks(
skip_cask_deps: nil,
require_sha: nil,
quarantine: nil,
quiet: nil
quiet: nil,
zap: nil
)
odie "Installing casks is supported only on macOS" unless OS.mac?

Expand All @@ -61,6 +67,7 @@ def self.install_casks(
skip_cask_deps: skip_cask_deps,
require_sha: require_sha,
quarantine: quarantine,
zap: zap,
}.compact

options[:quarantine] = true if options[:quarantine].nil?
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/cask/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def run
skip_cask_deps: args.skip_cask_deps?,
require_sha: args.require_sha?,
quarantine: args.quarantine?,
zap: args.zap?,
)
end

Expand All @@ -29,7 +30,8 @@ def self.reinstall_casks(
skip_cask_deps: nil,
binaries: nil,
require_sha: nil,
quarantine: nil
quarantine: nil,
zap: nil
)
require "cask/installer"

Expand All @@ -40,6 +42,7 @@ def self.reinstall_casks(
skip_cask_deps: skip_cask_deps,
require_sha: require_sha,
quarantine: quarantine,
zap: zap,
}.compact

options[:quarantine] = true if options[:quarantine].nil?
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Installer

def initialize(cask, command: SystemCommand, force: false,
skip_cask_deps: false, binaries: true, verbose: false,
require_sha: false, upgrade: false,
zap: false, require_sha: false, upgrade: false,
installed_as_dependency: false, quarantine: true,
verify_download_integrity: true, quiet: false)
@cask = cask
Expand All @@ -38,6 +38,7 @@ def initialize(cask, command: SystemCommand, force: false,
@skip_cask_deps = skip_cask_deps
@binaries = binaries
@verbose = verbose
@zap = zap
@require_sha = require_sha
@reinstall = false
@upgrade = upgrade
Expand All @@ -48,7 +49,7 @@ def initialize(cask, command: SystemCommand, force: false,
end

attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?,
:reinstall?, :upgrade?, :verbose?, :installed_as_dependency?,
:reinstall?, :upgrade?, :verbose?, :zap?, :installed_as_dependency?,
:quarantine?, :quiet?

def self.caveats(cask)
Expand Down Expand Up @@ -157,7 +158,8 @@ def uninstall_existing_cask
installed_cask = installed_caskfile.exist? ? CaskLoader.load(installed_caskfile) : @cask

# Always force uninstallation, ignore method parameter
Installer.new(installed_cask, verbose: verbose?, force: true, upgrade: upgrade?).uninstall
cask_installer = Installer.new(installed_cask, verbose: verbose?, force: true, upgrade: upgrade?)
zap? ? cask_installer.zap : cask_installer.uninstall
end

sig { returns(String) }
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def reinstall
require_sha: args.require_sha?,
skip_cask_deps: args.skip_cask_deps?,
quarantine: args.quarantine?,
zap: args.zap?,
)
end

Expand Down
7 changes: 6 additions & 1 deletion Library/Homebrew/test/cask/cmd/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@
"artifacts": [
[
"Caffeine.app"
]
],
{
"trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist",
"signal": {
}
}
],
"caveats": null,
"depends_on": {
Expand Down
25 changes: 25 additions & 0 deletions Library/Homebrew/test/cask/cmd/reinstall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@
}.to output(output).to_stdout
end

it "displays the reinstallation progress with zapping" do
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))

Cask::Installer.new(caffeine).install

output = Regexp.new <<~EOS
==> Downloading file:.*caffeine.zip
Already downloaded: .*--caffeine.zip
==> Implied `brew uninstall --cask local-caffeine`
==> Backing App 'Caffeine.app' up to '.*Caffeine.app'
==> Removing App '.*Caffeine.app'
==> Dispatching zap stanza
==> Trashing files:
.*org\.example\.caffeine\.plist
==> Removing all staged versions of Cask 'local-caffeine'
==> Installing Cask local-caffeine
==> Moving App 'Caffeine.app' to '.*Caffeine.app'
.*local-caffeine was successfully installed!
EOS

expect {
described_class.run("local-caffeine", "--zap")
}.to output(output).to_stdout
end

it "allows reinstalling a Cask" do
Cask::Cmd::Install.run("local-transmission")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
homepage "https://brew.sh/"

app "Caffeine.app"

zap trash: "#{TEST_FIXTURE_DIR}/cask/caffeine/org.example.caffeine.plist"
end