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").
This commit is contained in:
JBYoshi 2023-05-11 10:50:12 -05:00
parent 082017e93d
commit 2e8232de39
No known key found for this signature in database
GPG Key ID: AE4430116622D05D
2 changed files with 25 additions and 2 deletions

View File

@ -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

View File

@ -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