From b675024ce0bec75c74b46224efb8b38b1576a4ac Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 22 Jul 2018 18:11:41 +0200 Subject: [PATCH 1/2] Add failing test for `DirectoryUnpackStrategy`. --- Library/Homebrew/test/unpack_strategy_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Library/Homebrew/test/unpack_strategy_spec.rb b/Library/Homebrew/test/unpack_strategy_spec.rb index 14174a7ff1..a2a3e5a3c1 100644 --- a/Library/Homebrew/test/unpack_strategy_spec.rb +++ b/Library/Homebrew/test/unpack_strategy_spec.rb @@ -90,6 +90,21 @@ describe DirectoryUnpackStrategy do strategy.extract(to: unpack_dir) expect(unpack_dir/"symlink").to be_a_symlink end + + it "preserves permissions of contained files" do + FileUtils.chmod 0644, path/"file" + + strategy.extract(to: unpack_dir) + expect((unpack_dir/"file").stat.mode & 0777).to eq 0644 + end + + it "preserves the permissions of the destination directory" do + FileUtils.chmod 0700, path + FileUtils.chmod 0755, unpack_dir + + strategy.extract(to: unpack_dir) + expect(unpack_dir.stat.mode & 0777).to eq 0755 + end end describe UncompressedUnpackStrategy do From c29ab2d707c160fb246a2daf3439d9291f8ea4c9 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 22 Jul 2018 18:24:01 +0200 Subject: [PATCH 2/2] Fix `DirectoryUnpackStrategy` permissions. --- Library/Homebrew/unpack_strategy.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 99d93f863a..117a8105b1 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -96,7 +96,9 @@ class DirectoryUnpackStrategy < UnpackStrategy private def extract_to_dir(unpack_dir, basename:, verbose:) - FileUtils.cp_r File.join(path, "."), unpack_dir, preserve: true, verbose: verbose + path.children.each do |child| + FileUtils.copy_entry child, unpack_dir/child.basename, true, false + end end end