From b1fff3205584e1e42ae750b2af7ca17963929aa9 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Thu, 23 Jul 2015 14:09:32 +0800 Subject: BottleLoader: check version mismatch Closes Homebrew/homebrew#42049. Signed-off-by: Xu Cheng --- Library/Homebrew/exceptions.rb | 10 ++++++++++ Library/Homebrew/formulary.rb | 5 +++++ 2 files changed, 15 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 59a374535..35dca72ac 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -301,3 +301,13 @@ class DuplicateResourceError < ArgumentError super "Resource #{resource.inspect} is defined more than once" end end + +class BottleVersionMismatchError < RuntimeError + def initialize bottle_file, bottle_version, formula, formula_version + super <<-EOS.undent + Bottle version mismatch + Bottle: #{bottle_file} (#{bottle_version}) + Formula: #{formula.full_name} (#{formula_version}) + EOS + end +end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e5b79972d..f1fed506e 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -90,6 +90,11 @@ class Formulary def get_formula(spec) formula = super formula.local_bottle_path = @bottle_filename + formula_version = formula.pkg_version + bottle_version = bottle_resolve_version(@bottle_filename) + unless formula_version == bottle_version + raise BottleVersionMismatchError.new(@bottle_filename, bottle_version, formula, formula_version) + end formula end end -- cgit v1.2.3