From 7aaa7f25ec712a2378a1e3cc2abb766c46579a53 Mon Sep 17 00:00:00 2001 From: miccal Date: Mon, 17 Aug 2020 05:36:37 +0800 Subject: [PATCH 1/2] cask/artifact/symlinked: do not overwrite files or symbolic links --- Library/Homebrew/cask/artifact/symlinked.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/artifact/symlinked.rb b/Library/Homebrew/cask/artifact/symlinked.rb index 7acb7e9694..b50c104dc4 100644 --- a/Library/Homebrew/cask/artifact/symlinked.rb +++ b/Library/Homebrew/cask/artifact/symlinked.rb @@ -44,10 +44,10 @@ module Cask "source '#{source}' is not there." end - if target.exist? && !target.symlink? + if target.exist? raise CaskError, - "It seems there is already #{self.class.english_article} " \ - "#{self.class.english_name} at '#{target}'; not linking." + "It seems there already exists #{self.class.english_article} " \ + "#{self.class.english_name} at '#{target}'; not overwriting." end ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'." From 5a74f1d971e39d95cab1b427ee5b2c4cd7960e47 Mon Sep 17 00:00:00 2001 From: miccal Date: Mon, 17 Aug 2020 19:39:27 +0800 Subject: [PATCH 2/2] binary_spec: fix test --- Library/Homebrew/test/cask/artifact/binary_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index d905e8d8f0..83098af32a 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -67,14 +67,16 @@ describe Cask::Artifact::Binary, :cask do expect(expected_path).not_to be :symlink? end - it "clobbers an existing symlink" do + it "avoids clobbering an existing symlink" do expected_path.make_symlink("/tmp") - artifacts.each do |artifact| - artifact.install_phase(command: NeverSudoSystemCommand, force: false) - end + expect { + artifacts.each do |artifact| + artifact.install_phase(command: NeverSudoSystemCommand, force: false) + end + }.to raise_error(Cask::CaskError) - expect(File.readlink(expected_path)).not_to eq("/tmp") + expect(File.readlink(expected_path)).to eq("/tmp") end it "creates parent directory if it doesn't exist" do