From b57fe84f81f9d1ae39a85ca4cfd910dbd2b81790 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 15 Apr 2021 12:17:55 +0100 Subject: [PATCH] Use long/readable tar flags. Also, use `--no-same-permissions` instead of `-o` (which does nothing without `-p` being passed and run as `root`) for the more explicit description of the behaviour we want. --- Library/Homebrew/test/unpack_strategy_spec.rb | 4 ++-- Library/Homebrew/unpack_strategy/tar.rb | 6 ++++-- Library/Homebrew/utils/bottles.rb | 2 +- Library/Homebrew/utils/tar.rb | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/test/unpack_strategy_spec.rb b/Library/Homebrew/test/unpack_strategy_spec.rb index 055fe3c96e..279bf48f37 100644 --- a/Library/Homebrew/test/unpack_strategy_spec.rb +++ b/Library/Homebrew/test/unpack_strategy_spec.rb @@ -32,7 +32,7 @@ describe UnpackStrategy do (mktmpdir/"file.tar").tap do |path| mktmpdir do |dir| (dir/directories).mkpath - system "tar", "-c", "-f", path, "-C", dir, "A/" + system "tar", "--create", "--file", path, "--directory", dir, "A/" end end } @@ -49,7 +49,7 @@ describe UnpackStrategy do (mktmpdir/basename).tap do |path| mktmpdir do |dir| FileUtils.touch dir/"file.txt" - system "tar", "-c", "-f", path, "-C", dir, "file.txt" + system "tar", "--create", "--file", path, "--directory", dir, "file.txt" end end } diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index a40ad8f45e..33d6ffcb46 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -30,7 +30,7 @@ module UnpackStrategy return false unless [Bzip2, Gzip, Lzip, Xz].any? { |s| s.can_extract?(path) } # Check if `tar` can list the contents, then it can also extract it. - stdout, _, status = system_command("tar", args: ["tf", path], print_stderr: false) + stdout, _, status = system_command("tar", args: ["--list", "--file", path], print_stderr: false) status.success? && !stdout.empty? end @@ -48,7 +48,9 @@ module UnpackStrategy end system_command! "tar", - args: ["xof", tar_path, "-C", unpack_dir], + args: ["--extract", "--no-same-owner", + "--file", tar_path, + "--directory", unpack_dir], verbose: verbose end end diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 5439e43d9b..4e809b1bec 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -47,7 +47,7 @@ module Utils end def file_from_bottle(bottle_file, file_path) - Utils.popen_read("tar", "--extract", "--stdout", "--file", bottle_file, file_path) + Utils.popen_read("tar", "--extract", "--to-stdout", "--file", bottle_file, file_path) end def resolve_formula_names(bottle_file) diff --git a/Library/Homebrew/utils/tar.rb b/Library/Homebrew/utils/tar.rb index ced4ed5234..53ce635a86 100644 --- a/Library/Homebrew/utils/tar.rb +++ b/Library/Homebrew/utils/tar.rb @@ -26,7 +26,7 @@ module Utils path = Pathname.new(path) return unless TAR_FILE_EXTENSIONS.include? path.extname - return if Utils.popen_read(executable, "-tf", path).match?(%r{/.*\.}) + return if Utils.popen_read(executable, "--list", "--file", path).match?(%r{/.*\.}) odie "#{path} is not a valid tar file!" end