Merge pull request #2038 from reitermarkus/non-existant-uninstall-script

Allow skipping `uninstall script:` when `--force` is passed.
This commit is contained in:
Markus Reiter 2017-02-17 01:10:32 +01:00 committed by GitHub
commit 18838109b7
2 changed files with 37 additions and 1 deletions

View File

@ -201,7 +201,15 @@ module Hbc
ohai "Running uninstall script #{executable}" ohai "Running uninstall script #{executable}"
raise CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil? raise CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil?
executable_path = @cask.staged_path.join(executable) executable_path = @cask.staged_path.join(executable)
@command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path)
unless executable_path.exist?
message = "uninstall script #{executable} does not exist"
raise CaskError, "#{message}." unless force
opoo "#{message}, skipping."
return
end
@command.run("/bin/chmod", args: ["--", "+x", executable_path])
@command.run(executable_path, script_arguments) @command.run(executable_path, script_arguments)
sleep 1 sleep 1
end end

View File

@ -60,6 +60,34 @@ describe Hbc::CLI::Uninstall do
expect(Hbc.appdir.join("MyFancyApp.app")).not_to exist expect(Hbc.appdir.join("MyFancyApp.app")).not_to exist
end end
it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do
cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb")
shutup do
Hbc::Installer.new(cask).install
end
expect(cask).to be_installed
Hbc.appdir.join("MyFancyApp.app").rmtree
expect {
shutup do
Hbc::CLI::Uninstall.run("with-uninstall-script-app")
end
}.to raise_error(Hbc::CaskError, /does not exist/)
expect(cask).to be_installed
expect {
shutup do
Hbc::CLI::Uninstall.run("with-uninstall-script-app", "--force")
end
}.not_to raise_error
expect(cask).not_to be_installed
end
describe "when multiple versions of a cask are installed" do describe "when multiple versions of a cask are installed" do
let(:token) { "versioned-cask" } let(:token) { "versioned-cask" }
let(:first_installed_version) { "1.2.3" } let(:first_installed_version) { "1.2.3" }