cask: try fix a couple of permission edge cases under multi-user

This commit is contained in:
Bo Anderson 2024-11-22 22:16:44 +00:00 committed by Mike McQuaid
parent 69b5df1154
commit 7308c105a4
No known key found for this signature in database
3 changed files with 26 additions and 11 deletions

View File

@ -116,12 +116,15 @@ module Cask
print_stderr: false, print_stderr: false,
).stdout ).stdout
if plist_status.start_with?("{") if plist_status.start_with?("{")
command.run!( result = command.run(
"/bin/launchctl", "/bin/launchctl",
args: ["remove", service], args: ["remove", service],
must_succeed: sudo,
sudo:, sudo:,
sudo_as_root: sudo, sudo_as_root: sudo,
) )
next if !sudo && !result.success?
sleep 1 sleep 1
end end
paths = [ paths = [

View File

@ -164,7 +164,16 @@ module Cask
source.dirname.mkpath source.dirname.mkpath
# We need to preserve extended attributes between copies. # We need to preserve extended attributes between copies.
command.run!("/bin/cp", args: ["-pR", target, source], sudo: !source.parent.writable?) # This may fail and need sudo if the source has files with restricted permissions.
[!source.parent.writable?, true].uniq.each do |sudo|
result = command.run(
"/bin/cp",
args: ["-pR", target, source],
must_succeed: sudo,
sudo:,
)
break if result.success?
end
delete(target, force:, command:, **options) delete(target, force:, command:, **options)
end end

View File

@ -49,9 +49,10 @@ RSpec.shared_examples "#uninstall_phase or #zap_phase" do
) )
.and_return(instance_double(SystemCommand::Result, stdout: unknown_response)) .and_return(instance_double(SystemCommand::Result, stdout: unknown_response))
expect(fake_system_command).to receive(:run!) expect(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"], sudo: false, sudo_as_root: false) .with("/bin/launchctl", args: ["remove", "my.fancy.package.service"],
.and_return(instance_double(SystemCommand::Result)) must_succeed: false, sudo: false, sudo_as_root: false)
.and_return(instance_double(SystemCommand::Result, success?: true))
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
end end
@ -76,9 +77,10 @@ RSpec.shared_examples "#uninstall_phase or #zap_phase" do
) )
.and_return(instance_double(SystemCommand::Result, stdout: service_info)) .and_return(instance_double(SystemCommand::Result, stdout: service_info))
expect(fake_system_command).to receive(:run!) expect(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"], sudo: true, sudo_as_root: true) .with("/bin/launchctl", args: ["remove", "my.fancy.package.service"],
.and_return(instance_double(SystemCommand::Result)) must_succeed: true, sudo: true, sudo_as_root: true)
.and_return(instance_double(SystemCommand::Result, success?: true))
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
end end
@ -136,9 +138,10 @@ RSpec.shared_examples "#uninstall_phase or #zap_phase" do
) )
.and_return(instance_double(SystemCommand::Result, stdout: service_info)) .and_return(instance_double(SystemCommand::Result, stdout: service_info))
expect(fake_system_command).to receive(:run!) expect(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service.12345"], sudo: true, sudo_as_root: true) .with("/bin/launchctl", args: ["remove", "my.fancy.package.service.12345"],
.and_return(instance_double(SystemCommand::Result)) must_succeed: true, sudo: true, sudo_as_root: true)
.and_return(instance_double(SystemCommand::Result, success?: true))
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
end end