Skip to content

Commit

Permalink
Only allow loading local bottles.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jul 13, 2024
1 parent 643fa83 commit 2601551
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2601551

Please sign in to comment.