From 643fa83a281f5391d593d469e990eccb3926e690 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 13 Jul 2024 11:36:03 -0400 Subject: [PATCH 1/2] Use `Downloadable` API in `FromBottleLoader`. --- Library/Homebrew/formulary.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 1a7afbd1e8df3..1ce3499f575ad 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -592,21 +592,21 @@ class FromBottleLoader < FormulaLoader def self.try_new(ref, from: T.unsafe(nil), warn: false) ref = ref.to_s - new(ref) if HOMEBREW_BOTTLES_EXTNAME_REGEX.match?(ref) + new(ref, warn:) if HOMEBREW_BOTTLES_EXTNAME_REGEX.match?(ref) end - def initialize(bottle_name) + def initialize(bottle_name, warn: false) case bottle_name when URL_START_REGEX # The name of the formula is found between the last slash and the last hyphen. formula_name = File.basename(bottle_name)[/(.+)-/, 1] - resource = Resource.new(formula_name) { url bottle_name } - resource.specs[:bottle] = true - downloader = resource.downloader - cached = downloader.cached_location.exist? - downloader.fetch - ohai "Pouring the cached bottle" if cached - @bottle_filename = downloader.cached_location + resource = Resource.new(formula_name) { url bottle_name, bottle: true } + if resource.downloaded? + ohai "Pouring the cached bottle" unless warn + else + resource.fetch + end + @bottle_filename = resource.cached_download else @bottle_filename = Pathname(bottle_name).realpath end From 2601551f3aa5c91aac8a11185274472e5986b146 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 13 Jul 2024 11:57:44 -0400 Subject: [PATCH 2/2] Only allow loading local bottles. --- Library/Homebrew/formulary.rb | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 1ce3499f575ad..ae7e9c11887ad 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -592,36 +592,23 @@ class FromBottleLoader < FormulaLoader def self.try_new(ref, from: T.unsafe(nil), warn: false) ref = ref.to_s - new(ref, warn:) if HOMEBREW_BOTTLES_EXTNAME_REGEX.match?(ref) + new(ref) if HOMEBREW_BOTTLES_EXTNAME_REGEX.match?(ref) && File.exist?(ref) end def initialize(bottle_name, warn: false) - case bottle_name - when URL_START_REGEX - # The name of the formula is found between the last slash and the last hyphen. - formula_name = File.basename(bottle_name)[/(.+)-/, 1] - resource = Resource.new(formula_name) { url bottle_name, bottle: true } - if resource.downloaded? - ohai "Pouring the cached bottle" unless warn - else - resource.fetch - end - @bottle_filename = resource.cached_download - else - @bottle_filename = Pathname(bottle_name).realpath - end - name, full_name = Utils::Bottles.resolve_formula_names @bottle_filename + @bottle_path = Pathname(bottle_name).realpath + name, full_name = Utils::Bottles.resolve_formula_names(@bottle_path) super name, Formulary.path(full_name) end def get_formula(spec, force_bottle: false, flags: [], ignore_errors: false, **) formula = begin - contents = Utils::Bottles.formula_contents(@bottle_filename, name:) + contents = Utils::Bottles.formula_contents(@bottle_path, name:) Formulary.from_contents(name, path, contents, spec, force_bottle:, flags:, ignore_errors:) rescue FormulaUnreadableError => e opoo <<~EOS - Unreadable formula in #{@bottle_filename}: + Unreadable formula in #{@bottle_path}: #{e} EOS super @@ -632,7 +619,7 @@ def get_formula(spec, force_bottle: false, flags: [], ignore_errors: false, **) EOS super end - formula.local_bottle_path = @bottle_filename + formula.local_bottle_path = @bottle_path formula end end