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

Install uninstall messages #2362

Merged
merged 6 commits into from
Apr 23, 2017
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
28 changes: 4 additions & 24 deletions Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,10 @@ def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
begin
cask = CaskLoader.load(cask_token)

installer = Installer.new(cask,
force: force,
skip_cask_deps: skip_cask_deps,
require_sha: require_sha)
installer.print_caveats
installer.fetch

if cask.installed?
# use copy of cask for uninstallation to avoid 'No such file or directory' bug
installed_cask = cask

# use the same cask file that was used for installation, if possible
if (installed_caskfile = installed_cask.installed_caskfile).exist?
installed_cask = CaskLoader.load_from_file(installed_caskfile)
end

# Always force uninstallation, ignore method parameter
Installer.new(installed_cask, force: true).uninstall
end

installer.stage
installer.install_artifacts
installer.enable_accessibility_access
puts installer.summary
Installer.new(cask,
force: force,
skip_cask_deps: skip_cask_deps,
require_sha: require_sha).reinstall

count += 1
rescue CaskUnavailableError => e
Expand Down
25 changes: 23 additions & 2 deletions Library/Homebrew/cask/lib/hbc/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false
@force = force
@skip_cask_deps = skip_cask_deps
@require_sha = require_sha
@reinstall = false
end

def self.print_caveats(cask)
Expand Down Expand Up @@ -76,20 +77,40 @@ def stage
def install
odebug "Hbc::Installer#install"

if @cask.installed? && !force
if @cask.installed? && !force && !@reinstall
raise CaskAlreadyInstalledAutoUpdatesError, @cask if @cask.auto_updates
raise CaskAlreadyInstalledError, @cask
end

print_caveats
fetch
uninstall_existing_cask if @reinstall

oh1 "Installing Cask #{@cask}"
stage
install_artifacts
enable_accessibility_access

puts summary
end

def reinstall
odebug "Hbc::Installer#reinstall"
@reinstall = true
install
end

def uninstall_existing_cask
return unless @cask.installed?

# use the same cask file that was used for installation, if possible
installed_caskfile = @cask.installed_caskfile
installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask

# Always force uninstallation, ignore method parameter
Installer.new(installed_cask, force: true).uninstall
end

def summary
s = ""
s << "#{Emoji.install_badge} " if Emoji.enabled?
Expand Down Expand Up @@ -307,7 +328,7 @@ def save_caskfile
end

def uninstall
odebug "Hbc::Installer#uninstall"
oh1 "Uninstalling Cask #{@cask}"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we ever use oh1 for Homebrew-Cask, so let's use ohai here, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intentional so that the parts of the reinstall process that are uninstall parts are clearly delineated from the install parts. oh1 groups these parts more obviously.

disable_accessibility_access
uninstall_artifacts
purge_versioned_files
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/cask/cli/install_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
describe Hbc::CLI::Install, :cask do
it "displays the installation progress" do
output = Regexp.new <<-EOS.undent
==> Downloading file:.*caffeine.zip
==> Verifying checksum for Cask local-caffeine
==> Installing Cask local-caffeine
==> Moving App 'Caffeine.app' to '.*Caffeine.app'.
.*local-caffeine was successfully installed!
EOS

expect {
Hbc::CLI::Install.run("local-caffeine")
}.to output(output).to_stdout
end

it "allows staging and activation of multiple Casks at once" do
shutup do
Hbc::CLI::Install.run("local-transmission", "local-caffeine")
Expand Down
23 changes: 23 additions & 0 deletions Library/Homebrew/test/cask/cli/reinstall_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
describe Hbc::CLI::Reinstall, :cask do
it "displays the reinstallation progress" do
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")

shutup do
Hbc::Installer.new(caffeine).install
end

output = Regexp.new <<-EOS.undent
==> Downloading file:.*caffeine.zip
Already downloaded: .*local-caffeine--1.2.3.zip
==> Verifying checksum for Cask local-caffeine
==> Uninstalling Cask local-caffeine
==> Removing App '.*Caffeine.app'.
==> Installing Cask local-caffeine
==> Moving App 'Caffeine.app' to '.*Caffeine.app'.
.*local-caffeine was successfully installed!
EOS

expect {
Hbc::CLI::Reinstall.run("local-caffeine")
}.to output(output).to_stdout
end

it "allows reinstalling a Cask" do
shutup do
Hbc::CLI::Install.run("local-transmission")
Expand Down
21 changes: 20 additions & 1 deletion Library/Homebrew/test/cask/cli/uninstall_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
describe Hbc::CLI::Uninstall, :cask do
it "displays the uninstallation progress" do
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")

shutup do
Hbc::Installer.new(caffeine).install
end

output = Regexp.new <<-EOS.undent
==> Uninstalling Cask local-caffeine
==> Removing App '.*Caffeine.app'.
EOS

expect {
Hbc::CLI::Uninstall.run("local-caffeine")
}.to output(output).to_stdout
end

it "shows an error when a bad Cask is provided" do
expect {
Hbc::CLI::Uninstall.run("notacask")
Expand All @@ -13,7 +30,9 @@

it "tries anyway on a non-present Cask when --force is given" do
expect {
Hbc::CLI::Uninstall.run("local-caffeine", "--force")
shutup do
Hbc::CLI::Uninstall.run("local-caffeine", "--force")
end
}.not_to raise_error
end

Expand Down