diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index fcd67a3d49..a21682050d 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -30,7 +30,17 @@ module UnpackStrategy private def extract_to_dir(unpack_dir, basename:, verbose:) - system_command! "tar", args: ["xf", path, "-C", unpack_dir] + Dir.mktmpdir do |tmpdir| + tar_path = path + + if DependencyCollector.tar_needs_xz_dependency? && Xz.can_extract?(path) + tmpdir = Pathname(tmpdir) + Xz.new(path).extract(to: tmpdir) + tar_path = tmpdir.children.first + end + + system_command! "tar", args: ["xf", tar_path, "-C", unpack_dir] + end end end end diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index c53d2681d5..99673e6159 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -24,19 +24,6 @@ module UnpackStrategy system_command! "unxz", args: [*quiet_flags, "-T0", "--", unpack_dir/basename], env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) } - extract_nested_tar(unpack_dir) - end - - def extract_nested_tar(unpack_dir) - 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 - Tar.new(tmpdir/tar.basename).extract(to: unpack_dir) - end end end end