From 22ddec85b01d6d2e061b94938a57e2773a5c282b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 18 Jul 2018 13:02:32 +0200 Subject: [PATCH 1/2] Add failing test. --- Library/Homebrew/test/unpack_strategy_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Library/Homebrew/test/unpack_strategy_spec.rb b/Library/Homebrew/test/unpack_strategy_spec.rb index 4d31c7604..1eb9dc3b5 100644 --- a/Library/Homebrew/test/unpack_strategy_spec.rb +++ b/Library/Homebrew/test/unpack_strategy_spec.rb @@ -59,6 +59,22 @@ describe UnpackStrategy do end end +describe DirectoryUnpackStrategy do + let(:path) { + mktmpdir.tap do |path| + FileUtils.touch path/"file" + FileUtils.ln_s "file", path/"symlink" + end + } + subject(:strategy) { described_class.new(path) } + let(:unpack_dir) { mktmpdir } + + it "does not follow symlinks" do + strategy.extract(to: unpack_dir) + expect(unpack_dir/"symlink").to be_a_symlink + end +end + describe UncompressedUnpackStrategy do let(:path) { (mktmpdir/"test").tap do |path| From 67c30b8372541131d3d78f385e68ac79f4dddf49 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 18 Jul 2018 13:03:29 +0200 Subject: [PATCH 2/2] Fix `DirectoryUnpackStrategy` following symlinks. --- Library/Homebrew/unpack_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 84def55eb..5062deb5f 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -96,7 +96,7 @@ class DirectoryUnpackStrategy < UnpackStrategy private def extract_to_dir(unpack_dir, basename:) - FileUtils.cp_r path.children, unpack_dir, preserve: true + FileUtils.cp_r File.join(path, "."), unpack_dir, preserve: true end end