From 96cd1c058e93d41636c2d868b6bed80212b19ae3 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 15 Apr 2021 12:16:26 +0100 Subject: [PATCH] utils/bottles: tweak/improve some of the API. --- Library/Homebrew/dev-cmd/bottle.rb | 4 ++-- Library/Homebrew/utils/bottles.rb | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 43676365ed..a2c2a4f0bb 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -325,10 +325,10 @@ module Homebrew bottle_path = f.local_bottle_path local_filename = bottle_path.basename.to_s - tab_path = Utils::Bottles.receipt_path(f.local_bottle_path) + tab_path = Utils::Bottles.receipt_path(bottle_path) raise "This bottle does not contain the file INSTALL_RECEIPT.json: #{bottle_path}" unless tab_path - tab_json = Utils.safe_popen_read("tar", "xfO", f.local_bottle_path, tab_path) + tab_json = Utils::Bottles.file_from_bottle(bottle_path, tab_path) tab = Tab.from_file_content(tab_json, tab_path) _, _, bottle_cellar = Formula[f.name].bottle_specification.checksum_for(bottle_tag, no_older_versions: true) diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 4a0d38b0b1..5439e43d9b 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -40,23 +40,20 @@ module Utils HOMEBREW_BOTTLES_EXTNAME_REGEX.match(filename).to_a end - def bottle_file_list(bottle_file) - @bottle_file_list ||= {} - @bottle_file_list[bottle_file] ||= Utils.popen_read("tar", "-tzf", bottle_file) - .lines - .map(&:chomp) - end - def receipt_path(bottle_file) bottle_file_list(bottle_file).find do |line| line =~ %r{.+/.+/INSTALL_RECEIPT.json} end end + def file_from_bottle(bottle_file, file_path) + Utils.popen_read("tar", "--extract", "--stdout", "--file", bottle_file, file_path) + end + def resolve_formula_names(bottle_file) name = bottle_file_list(bottle_file).first.to_s.split("/").first full_name = if (receipt_file_path = receipt_path(bottle_file)) - receipt_file = Utils.popen_read("tar", "-xOzf", bottle_file, receipt_file_path) + receipt_file = file_from_bottle(bottle_file, receipt_file_path) tap = Tab.from_file_content(receipt_file, "#{bottle_file}/#{receipt_file_path}").tap "#{tap}/#{name}" if tap.present? && !tap.core_tap? elsif (bottle_json_path = Pathname(bottle_file.sub(/\.tar\.gz$/, ".json"))) && @@ -80,7 +77,7 @@ module Utils name: resolve_formula_names(bottle_file)[0]) bottle_version = resolve_version bottle_file formula_path = "#{name}/#{bottle_version}/.brew/#{name}.rb" - contents = Utils.popen_read "tar", "-xOzf", bottle_file, formula_path + contents = file_from_bottle(bottle_file, formula_path) raise BottleFormulaUnavailableError.new(bottle_file, formula_path) unless $CHILD_STATUS.success? contents @@ -94,6 +91,15 @@ module Utils filename&.url_encode end end + + private + + def bottle_file_list(bottle_file) + @bottle_file_list ||= {} + @bottle_file_list[bottle_file] ||= Utils.popen_read("tar", "--list", "--file", bottle_file) + .lines + .map(&:chomp) + end end # Denotes the arch and OS of a bottle.