Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ def uninstall_launchctl(*services, command: nil, **_)
print_stderr: false,
).stdout
if plist_status.start_with?("{")
command.run!(
result = command.run(
"/bin/launchctl",
args: ["remove", service],
must_succeed: sudo,
sudo:,
sudo_as_root: sudo,
)
next if !sudo && !result.success?

sleep 1
end
paths = [
Expand Down
11 changes: 10 additions & 1 deletion Library/Homebrew/cask/artifact/moved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,16 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options)
source.dirname.mkpath

# 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)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
)
.and_return(instance_double(SystemCommand::Result, stdout: unknown_response))

expect(fake_system_command).to receive(:run!)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"], sudo: false, sudo_as_root: false)
.and_return(instance_double(SystemCommand::Result))
expect(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"],
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)
end
Expand All @@ -76,9 +77,10 @@
)
.and_return(instance_double(SystemCommand::Result, stdout: service_info))

expect(fake_system_command).to receive(:run!)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"], sudo: true, sudo_as_root: true)
.and_return(instance_double(SystemCommand::Result))
expect(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"],
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)
end
Expand Down Expand Up @@ -136,9 +138,10 @@
)
.and_return(instance_double(SystemCommand::Result, stdout: service_info))

expect(fake_system_command).to receive(:run!)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service.12345"], sudo: true, sudo_as_root: true)
.and_return(instance_double(SystemCommand::Result))
expect(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service.12345"],
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)
end
Expand Down
Loading