utils/bottles: tweak/improve some of the API.

This commit is contained in:
Mike McQuaid 2021-04-15 12:16:26 +01:00
parent a28dda5062
commit 96cd1c058e
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
2 changed files with 17 additions and 11 deletions

View File

@ -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)

View File

@ -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.