Skip to content

Commit

Permalink
unpack_strategy: fix unpack Dir.mktmpdir group
Browse files Browse the repository at this point in the history
Otherwise the files will be unpacked with group wheel on macOS which
gets copied over when running `cp -al`.
  • Loading branch information
cho-m committed Oct 11, 2024
1 parent 3ba4b8d commit c8044fd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio
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
opoo "Failed setting group \"#{Etc.getgrgid(group_id)&.name}\" on #{tmp_unpack_dir}"
end

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

children = tmp_unpack_dir.children
Expand Down

0 comments on commit c8044fd

Please sign in to comment.