From 0bbfa434cf4bb50e2a8aabc7f0ebf80755f47707 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 1 Apr 2024 09:49:10 +0100 Subject: [PATCH] unpack_strategy/dmg: fix permissions when needed. `ditto` behaves weirdly when the EUID is different from the UID. This fix ensures that the BOM file is written with the correct permissions in this case. --- Library/Homebrew/unpack_strategy/dmg.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index c207e58edd..92c7f8ca49 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -147,8 +147,16 @@ module UnpackStrategy verbose: end + bomfile_path = T.must(bomfile.path) + + # Ditto will try to write as the UID, not the EUID and the Tempfile has 0700 permissions. + if Process.euid != Process.uid + FileUtils.chown(nil, Process.gid, bomfile_path) + FileUtils.chmod "g+rw", bomfile_path + end + system_command!("ditto", - args: ["--bom", bomfile.path, "--", path, unpack_dir], + args: ["--bom", bomfile_path, "--", path, unpack_dir], verbose:) FileUtils.chmod "u+w", Pathname.glob(unpack_dir/"**/*", File::FNM_DOTMATCH).reject(&:symlink?)