Skip to content

Commit 44a01a9

Browse files
committed
bundle: write to tab through the wrapper
1 parent 110b93e commit 44a01a9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Library/Homebrew/bundle.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ def mark_as_installed_on_request!(entries)
185185
installed_formulae = Formula.installed_formula_names
186186
return if installed_formulae.empty?
187187

188-
entries.each do |entry|
188+
use_brew_tab = T.let(false, T::Boolean)
189+
190+
formulae_to_update = entries.filter_map do |entry|
189191
next if entry.type != :brew
190192

191193
name = entry.name
@@ -195,9 +197,22 @@ def mark_as_installed_on_request!(entries)
195197
next if tab.tabfile.blank? || !tab.tabfile.exist?
196198
next if tab.installed_on_request
197199

200+
next name if use_brew_tab
201+
198202
tab.installed_on_request = true
199-
tab.write
203+
204+
begin
205+
tab.write
206+
nil
207+
rescue Errno::EACCES
208+
# Some wrappers might treat `brew bundle` with lower permissions due to its execution of user code.
209+
# Running through `brew tab` ensures proper privilege escalation by going through the wrapper again.
210+
use_brew_tab = true
211+
name
212+
end
200213
end
214+
215+
brew "tab", "--installed-on-request", *formulae_to_update if use_brew_tab
201216
end
202217
end
203218
end

0 commit comments

Comments
 (0)