From 2e8232de39721f542b4c7f8ffbb22c7a922cd8d1 Mon Sep 17 00:00:00 2001 From: JBYoshi <12983479+JBYoshi@users.noreply.github.com> Date: Thu, 11 May 2023 10:50:12 -0500 Subject: [PATCH] Replace wildcard copy with a loop over children. Fixes one of the errors in https://github.com/orgs/Homebrew/discussions/4498 (specifically "cp: [...].app/*: No such file or directory"). --- Library/Homebrew/cask/artifact/moved.rb | 6 ++++-- .../Homebrew/test/cask/artifact/app_spec.rb | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 48861a0f61..ee878de0a5 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -94,8 +94,10 @@ module Cask if target.writable? source.children.each { |child| FileUtils.move(child, target + child.basename) } else - command.run!("/bin/cp", args: ["-pR", "#{source}/*", "#{source}/.*", "#{target}/"], - sudo: true) + source.children.each do |child| + command.run!("/bin/cp", args: ["-pR", child, target + child.basename], + sudo: true) + end end Quarantine.copy_xattrs(source, target) source.rmtree diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 796f03f19f..da92098599 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -334,5 +334,26 @@ describe Cask::Artifact::App, :cask do expect(contents_path).to exist end + + it "properly handles non-writable directories" do + install_phase + + contents_path = target_path.join("Contents") + + allow(target_path).to receive(:writable?).and_return false + allow(command).to receive(:run!).and_call_original + allow(command).to receive(:run!) + .with("/bin/cp", args: ["-pR", source_path.join("Contents"), contents_path], + sudo: true) + .and_wrap_original do |original_method, *args, **kwargs| + original_method.call(*args, sudo_as_root: false, **kwargs) + end + + app.uninstall_phase(command: command, force: force, successor: cask) + expect(contents_path).not_to exist + + app.install_phase(command: command, adopt: adopt, force: force, predecessor: cask) + expect(contents_path).to exist + end end end