diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 53d09bed19..7347cb2d45 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -114,7 +114,7 @@ module Cask source.dirname.mkpath # We need to preserve extended attributes between copies. - command.run!("/bin/cp", args: ["-pR", target, source], sudo: !target.parent.writable?) + command.run!("/bin/cp", args: ["-pR", target, source], sudo: !source.parent.writable?) delete(target, force: force, command: command, **options) end diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index d9960b82e4..53ffbc43ca 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -263,6 +263,11 @@ describe Cask::Artifact::App, :cask do end describe "uninstall_phase" do + after do + FileUtils.chmod 0755, target_path if target_path.exist? + FileUtils.chmod 0755, source_path if source_path.exist? + end + it "deletes managed apps" do install_phase @@ -272,6 +277,16 @@ describe Cask::Artifact::App, :cask do expect(target_path).not_to exist end + + it "backs up read-only managed apps" do + install_phase + + FileUtils.chmod 0544, target_path + + expect { uninstall_phase }.to raise_error(Errno::ENOTEMPTY) + + expect(source_path).to be_a_directory + end end describe "summary" do