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