From ec7e22e16fbaa09ca01b8e2fff84ba5c7613b5b0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 9 Jul 2018 21:20:00 +0200 Subject: [PATCH] Fix `XzUnpackStrategy`. --- Library/Homebrew/unpack_strategy.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index a23406805f..ff41938fc0 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -151,7 +151,7 @@ class CompressUnpackStrategy < TarUnpackStrategy end end -class XzUnpackStrategy < TarUnpackStrategy +class XzUnpackStrategy < UnpackStrategy def self.can_extract?(path:, magic_number:) magic_number.match?(/\A\xFD7zXZ\x00/n) end @@ -159,13 +159,23 @@ class XzUnpackStrategy < TarUnpackStrategy private def extract_to_dir(unpack_dir, basename:) - if DependencyCollector.tar_needs_xz_dependency? - unpack_path = unpack_dir/path.basename - FileUtils.cp path, unpack_path, preserve: true + unpack_path = unpack_dir/path.basename + FileUtils.cp path, unpack_path, preserve: true - safe_system Formula["xz"].opt_bin/"xz", "-d", "-q", "-T0", unpack_path - else - super + safe_system Formula["xz"].opt_bin/"xz", "-d", "-q", "-T0", unpack_path + + extract_nested_tar(unpack_dir, basename: basename) + end + + def extract_nested_tar(unpack_dir, basename:) + return unless DependencyCollector.tar_needs_xz_dependency? + return if (children = unpack_dir.children).count != 1 + return if (tar = children.first).extname != ".tar" + + Dir.mktmpdir do |tmpdir| + tmpdir = Pathname(tmpdir) + FileUtils.mv tar, tmpdir/tar.basename + TarUnpackStrategy.new(tmpdir/tar.basename).extract(to: unpack_dir, basename: basename) end end end