Skip to content

Commit e78a0ad

Browse files
authored
Merge pull request #18805 from Homebrew/perm-fixes
cask: try fix a couple of permission edge cases under multi-user
2 parents f94c7d0 + 7308c10 commit e78a0ad

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

Library/Homebrew/cask/artifact/abstract_uninstall.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ def uninstall_launchctl(*services, command: nil, **_)
116116
print_stderr: false,
117117
).stdout
118118
if plist_status.start_with?("{")
119-
command.run!(
119+
result = command.run(
120120
"/bin/launchctl",
121121
args: ["remove", service],
122+
must_succeed: sudo,
122123
sudo:,
123124
sudo_as_root: sudo,
124125
)
126+
next if !sudo && !result.success?
127+
125128
sleep 1
126129
end
127130
paths = [

Library/Homebrew/cask/artifact/moved.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,16 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options)
164164
source.dirname.mkpath
165165

166166
# We need to preserve extended attributes between copies.
167-
command.run!("/bin/cp", args: ["-pR", target, source], sudo: !source.parent.writable?)
167+
# This may fail and need sudo if the source has files with restricted permissions.
168+
[!source.parent.writable?, true].uniq.each do |sudo|
169+
result = command.run(
170+
"/bin/cp",
171+
args: ["-pR", target, source],
172+
must_succeed: sudo,
173+
sudo:,
174+
)
175+
break if result.success?
176+
end
168177

169178
delete(target, force:, command:, **options)
170179
end

Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
)
5050
.and_return(instance_double(SystemCommand::Result, stdout: unknown_response))
5151

52-
expect(fake_system_command).to receive(:run!)
53-
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"], sudo: false, sudo_as_root: false)
54-
.and_return(instance_double(SystemCommand::Result))
52+
expect(fake_system_command).to receive(:run)
53+
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"],
54+
must_succeed: false, sudo: false, sudo_as_root: false)
55+
.and_return(instance_double(SystemCommand::Result, success?: true))
5556

5657
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
5758
end
@@ -76,9 +77,10 @@
7677
)
7778
.and_return(instance_double(SystemCommand::Result, stdout: service_info))
7879

79-
expect(fake_system_command).to receive(:run!)
80-
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"], sudo: true, sudo_as_root: true)
81-
.and_return(instance_double(SystemCommand::Result))
80+
expect(fake_system_command).to receive(:run)
81+
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service"],
82+
must_succeed: true, sudo: true, sudo_as_root: true)
83+
.and_return(instance_double(SystemCommand::Result, success?: true))
8284

8385
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
8486
end
@@ -136,9 +138,10 @@
136138
)
137139
.and_return(instance_double(SystemCommand::Result, stdout: service_info))
138140

139-
expect(fake_system_command).to receive(:run!)
140-
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service.12345"], sudo: true, sudo_as_root: true)
141-
.and_return(instance_double(SystemCommand::Result))
141+
expect(fake_system_command).to receive(:run)
142+
.with("/bin/launchctl", args: ["remove", "my.fancy.package.service.12345"],
143+
must_succeed: true, sudo: true, sudo_as_root: true)
144+
.and_return(instance_double(SystemCommand::Result, success?: true))
142145

143146
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
144147
end

0 commit comments

Comments
 (0)