From c8044fd67dd59f7023430546ca4fc96bb5723179 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Fri, 11 Oct 2024 13:21:43 -0400 Subject: [PATCH] unpack_strategy: fix unpack Dir.mktmpdir group Otherwise the files will be unpacked with group wheel on macOS which gets copied over when running `cp -al`. --- Library/Homebrew/unpack_strategy.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index e234442d9ecff..fa3f10f9e8e03 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -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" + 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