Merge pull request #18548 from Homebrew/unpack_strategy-group-fix

unpack_strategy: fix unpack Dir.mktmpdir group
This commit is contained in:
Bo Anderson 2024-10-14 07:48:21 +01:00 committed by GitHub
commit 70672606c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,6 +160,27 @@ module UnpackStrategy
Dir.mktmpdir("homebrew-unpack", HOMEBREW_TEMP) do |tmp_unpack_dir| Dir.mktmpdir("homebrew-unpack", HOMEBREW_TEMP) do |tmp_unpack_dir|
tmp_unpack_dir = Pathname(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"
group_name = begin
Etc.getgrgid(group_id)&.name
rescue ArgumentError
# Cover for misconfigured NSS setups
nil
end
opoo "Failed setting group \"#{group_name || group_id}\" on #{tmp_unpack_dir}"
end
extract(to: tmp_unpack_dir, basename:, verbose:) extract(to: tmp_unpack_dir, basename:, verbose:)
children = tmp_unpack_dir.children children = tmp_unpack_dir.children