Extract 'verify_download_integrity' method

In order to support more than just MD5 verification, extract 'verify_download'
into a separate method.
This commit is contained in:
Adam Vandenberg 2009-07-31 11:05:23 -07:00 committed by Max Howell
parent 182ce1eff6
commit fea89daae6

View File

@ -31,11 +31,11 @@ class AbstractFormula
private private
class <<self class <<self
attr_reader :url, :version, :md5, :url, :homepage attr_reader :url, :version, :md5, :url, :homepage, :sha1
end end
public public
attr_reader :url, :version, :md5, :url, :homepage, :name attr_reader :url, :version, :url, :homepage, :name
# reimplement if your package has dependencies # reimplement if your package has dependencies
def deps def deps
@ -54,6 +54,7 @@ public
@url=self.class.url unless @url @url=self.class.url unless @url
@homepage=self.class.homepage unless @homepage @homepage=self.class.homepage unless @homepage
@md5=self.class.md5 unless @md5 @md5=self.class.md5 unless @md5
@sha1=self.class.sha1 unless @sha1
raise "@url.nil?" if @url.nil? raise "@url.nil?" if @url.nil?
end end
@ -102,6 +103,22 @@ public
"-DCMAKE_INSTALL_PREFIX='#{prefix}' -DCMAKE_BUILD_TYPE=None" "-DCMAKE_INSTALL_PREFIX='#{prefix}' -DCMAKE_BUILD_TYPE=None"
end end
def verify_download_integrity fn
require 'digest'
type='MD5'
type='SHA1' if @sha1
supplied=eval "@#{type.downcase}"
hash=eval("Digest::#{type}").hexdigest(fn.read)
if supplied
raise "#{type} mismatch: #{hash}" unless supplied.upcase == hash.upcase
else
opoo "Cannot verify package integrity"
puts "The formula did not provide a download checksum"
puts "For your reference the #{type} is: #{hash}"
end
end
# yields self with current working directory set to the uncompressed tarball # yields self with current working directory set to the uncompressed tarball
def brew def brew
ohai "Downloading #{@url}" ohai "Downloading #{@url}"
@ -110,14 +127,7 @@ public
tmp=nil tmp=nil
tgz=Pathname.new(fetch()).realpath tgz=Pathname.new(fetch()).realpath
begin begin
md5=`md5 -q "#{tgz}"`.strip verify_download_integrity tgz
if @md5 and not @md5.empty?
raise "MD5 mismatch: #{md5}" unless md5 == @md5.downcase
else
opoo "Cannot verify package integrity"
puts "The formula did not provide a download checksum"
puts "For your reference the MD5 is: #{md5}"
end
# we make an additional subdirectory so know exactly what we are # we make an additional subdirectory so know exactly what we are
# recursively deleting later # recursively deleting later