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

unpack_strategy: fix unpack Dir.mktmpdir group #18548

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
21 changes: 21 additions & 0 deletions Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@
Dir.mktmpdir("homebrew-unpack", HOMEBREW_TEMP) do |tmp_unpack_dir|
tmp_unpack_dir = Pathname(tmp_unpack_dir)

# Make sure files inside the temporary directory have the same group as the brew instance.
#
# @see https://github.com/Homebrew/brew/blob/4.4.0/Library/Homebrew/mktemp.rb#L57-L72
group_id = if HOMEBREW_BREW_FILE.grpowned?
HOMEBREW_BREW_FILE.stat.gid
else
Process.gid
end
begin
tmp_unpack_dir.chown(nil, group_id)
rescue Errno::EPERM
require "etc"

Check warning on line 174 in Library/Homebrew/unpack_strategy.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy.rb#L174

Added line #L174 was not covered by tests
group_name = begin
Etc.getgrgid(group_id)&.name
rescue ArgumentError
# Cover for misconfigured NSS setups
nil

Check warning on line 179 in Library/Homebrew/unpack_strategy.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy.rb#L179

Added line #L179 was not covered by tests
end
opoo "Failed setting group \"#{group_name || group_id}\" on #{tmp_unpack_dir}"

Check warning on line 181 in Library/Homebrew/unpack_strategy.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy.rb#L181

Added line #L181 was not covered by tests
end

extract(to: tmp_unpack_dir, basename:, verbose:)

children = tmp_unpack_dir.children
Expand Down
Loading