Merge pull request #1590 from reitermarkus/fail-if-app-source-already-exists
Fail if cask source already exists.
This commit is contained in:
commit
5cc7acee17
@ -42,12 +42,8 @@ module Hbc
|
||||
|
||||
def preflight_checks
|
||||
if Utils.path_occupied?(target)
|
||||
if force
|
||||
ohai(warning_target_exists { |s| s << "overwriting." })
|
||||
else
|
||||
ohai(warning_target_exists { |s| s << "not moving." })
|
||||
return false
|
||||
end
|
||||
raise CaskError, warning_target_exists << "." unless force
|
||||
opoo(warning_target_exists { |s| s << "overwriting." })
|
||||
end
|
||||
unless source.exist?
|
||||
message = "It seems the #{self.class.artifact_english_name} source is not there: '#{source}'"
|
||||
|
||||
@ -39,8 +39,7 @@ module Hbc
|
||||
|
||||
def preflight_checks(source, target)
|
||||
if target.exist? && !self.class.islink?(target)
|
||||
ohai "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking."
|
||||
return false
|
||||
raise CaskError, "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking."
|
||||
end
|
||||
unless source.exist?
|
||||
raise CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'"
|
||||
|
||||
@ -35,6 +35,8 @@ module Hbc
|
||||
rescue CaskNoShasumError => e
|
||||
opoo e.message
|
||||
count += 1
|
||||
rescue CaskError => e
|
||||
onoe e.message
|
||||
end
|
||||
end
|
||||
count.zero? ? nil : count == cask_tokens.length
|
||||
|
||||
@ -26,9 +26,11 @@ describe Hbc::Artifact::Binary do
|
||||
it "avoids clobbering an existing binary by linking over it" do
|
||||
FileUtils.touch expected_path
|
||||
|
||||
shutup do
|
||||
Hbc::Artifact::Binary.new(cask).install_phase
|
||||
end
|
||||
expect {
|
||||
shutup do
|
||||
Hbc::Artifact::Binary.new(cask).install_phase
|
||||
end
|
||||
}.to raise_error(Hbc::CaskError)
|
||||
|
||||
expect(expected_path).not_to be :symlink?
|
||||
end
|
||||
|
||||
@ -69,9 +69,9 @@ describe Hbc::Artifact::App do
|
||||
it "avoids clobbering an existing app by moving over it" do
|
||||
target_path.mkpath
|
||||
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; not moving.
|
||||
EOS
|
||||
err = install_phase.must_raise(Hbc::CaskError)
|
||||
|
||||
err.message.must_equal("It seems there is already an App at '#{target_path}'.")
|
||||
|
||||
source_path.must_be :directory?
|
||||
target_path.must_be :directory?
|
||||
|
||||
@ -71,9 +71,9 @@ describe Hbc::Artifact::App do
|
||||
end
|
||||
|
||||
it "avoids clobbering an existing app" do
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; not moving.
|
||||
EOS
|
||||
err = install_phase.must_raise(Hbc::CaskError)
|
||||
|
||||
err.message.must_equal("It seems there is already an App at '#{target_path}'.")
|
||||
|
||||
source_path.must_be :directory?
|
||||
target_path.must_be :directory?
|
||||
@ -92,12 +92,17 @@ describe Hbc::Artifact::App do
|
||||
|
||||
describe "target is both writable and user-owned" do
|
||||
it "overwrites the existing app" do
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; overwriting.
|
||||
stdout = <<-EOS.undent
|
||||
==> Removing App: '#{target_path}'
|
||||
==> Moving App 'Caffeine.app' to '#{target_path}'
|
||||
EOS
|
||||
|
||||
stderr = <<-EOS.undent
|
||||
Warning: It seems there is already an App at '#{target_path}'; overwriting.
|
||||
EOS
|
||||
|
||||
install_phase.must_output(stdout, stderr)
|
||||
|
||||
source_path.wont_be :exist?
|
||||
target_path.must_be :directory?
|
||||
|
||||
@ -131,12 +136,17 @@ describe Hbc::Artifact::App do
|
||||
command.expect_and_pass_through(chmod_cmd)
|
||||
command.expect_and_pass_through(chmod_n_cmd)
|
||||
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; overwriting.
|
||||
stdout = <<-EOS.undent
|
||||
==> Removing App: '#{target_path}'
|
||||
==> Moving App 'Caffeine.app' to '#{target_path}'
|
||||
EOS
|
||||
|
||||
stderr = <<-EOS.undent
|
||||
Warning: It seems there is already an App at '#{target_path}'; overwriting.
|
||||
EOS
|
||||
|
||||
install_phase.must_output(stdout, stderr)
|
||||
|
||||
source_path.wont_be :exist?
|
||||
target_path.must_be :directory?
|
||||
|
||||
@ -161,9 +171,9 @@ describe Hbc::Artifact::App do
|
||||
end
|
||||
|
||||
it "leaves the target alone" do
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; not moving.
|
||||
EOS
|
||||
err = install_phase.must_raise(Hbc::CaskError)
|
||||
|
||||
err.message.must_equal("It seems there is already an App at '#{target_path}'.")
|
||||
|
||||
File.symlink?(target_path).must_equal true
|
||||
end
|
||||
@ -172,12 +182,17 @@ describe Hbc::Artifact::App do
|
||||
let(:force) { true }
|
||||
|
||||
it "overwrites the existing app" do
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path}'; overwriting.
|
||||
stdout = <<-EOS.undent
|
||||
==> Removing App: '#{target_path}'
|
||||
==> Moving App 'Caffeine.app' to '#{target_path}'
|
||||
EOS
|
||||
|
||||
stderr = <<-EOS.undent
|
||||
Warning: It seems there is already an App at '#{target_path}'; overwriting.
|
||||
EOS
|
||||
|
||||
install_phase.must_output(stdout, stderr)
|
||||
|
||||
source_path.wont_be :exist?
|
||||
target_path.must_be :directory?
|
||||
|
||||
|
||||
@ -34,8 +34,10 @@ describe Hbc::Artifact::Artifact do
|
||||
it "avoids clobbering an existing artifact" do
|
||||
target_path.mkpath
|
||||
|
||||
shutup do
|
||||
install_phase.call
|
||||
assert_raises Hbc::CaskError do
|
||||
shutup do
|
||||
install_phase.call
|
||||
end
|
||||
end
|
||||
|
||||
source_path.must_be :directory?
|
||||
|
||||
@ -33,8 +33,10 @@ describe Hbc::Artifact::Suite do
|
||||
it "avoids clobbering an existing suite by moving over it" do
|
||||
target_path.mkpath
|
||||
|
||||
shutup do
|
||||
install_phase.call
|
||||
assert_raises Hbc::CaskError do
|
||||
shutup do
|
||||
install_phase.call
|
||||
end
|
||||
end
|
||||
|
||||
source_path.must_be :directory?
|
||||
|
||||
@ -64,10 +64,13 @@ describe Hbc::Artifact::App do
|
||||
it "when the first app of two already exists" do
|
||||
target_path_mini.mkpath
|
||||
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> It seems there is already an App at '#{target_path_mini}'; not moving.
|
||||
==> Moving App 'Caffeine Pro.app' to '#{target_path_pro}'
|
||||
EOS
|
||||
err = assert_raises Hbc::CaskError do
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> Moving App 'Caffeine Pro.app' to '#{target_path_pro}'
|
||||
EOS
|
||||
end
|
||||
|
||||
err.message.must_equal("It seems there is already an App at '#{target_path_mini}'.")
|
||||
|
||||
source_path_mini.must_be :directory?
|
||||
target_path_mini.must_be :directory?
|
||||
@ -77,10 +80,13 @@ describe Hbc::Artifact::App do
|
||||
it "when the second app of two already exists" do
|
||||
target_path_pro.mkpath
|
||||
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> Moving App 'Caffeine Mini.app' to '#{target_path_mini}'
|
||||
==> It seems there is already an App at '#{target_path_pro}'; not moving.
|
||||
EOS
|
||||
err = assert_raises Hbc::CaskError do
|
||||
install_phase.must_output <<-EOS.undent
|
||||
==> Moving App 'Caffeine Mini.app' to '#{target_path_mini}'
|
||||
EOS
|
||||
end
|
||||
|
||||
err.message.must_equal("It seems there is already an App at '#{target_path_pro}'.")
|
||||
|
||||
source_path_pro.must_be :directory?
|
||||
target_path_pro.must_be :directory?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user