aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2009-07-31 11:05:23 -0700
committerMax Howell2009-08-10 16:14:43 +0100
commitfea89daae6e7b2d6bcae4b89becc819a1df4aac9 (patch)
treed7d476b2bb7210e68833fcca42863ab3033ec5b3 /Library
parent182ce1eff69eb9ee4133a5e3abebbd27a9909986 (diff)
downloadbrew-fea89daae6e7b2d6bcae4b89becc819a1df4aac9.tar.bz2
Extract 'verify_download_integrity' method
In order to support more than just MD5 verification, extract 'verify_download' into a separate method.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb30
1 files changed, 20 insertions, 10 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 56525be1e..1b20c9640 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -31,11 +31,11 @@ class AbstractFormula
private
class <<self
- attr_reader :url, :version, :md5, :url, :homepage
+ attr_reader :url, :version, :md5, :url, :homepage, :sha1
end
public
- attr_reader :url, :version, :md5, :url, :homepage, :name
+ attr_reader :url, :version, :url, :homepage, :name
# reimplement if your package has dependencies
def deps
@@ -54,6 +54,7 @@ public
@url=self.class.url unless @url
@homepage=self.class.homepage unless @homepage
@md5=self.class.md5 unless @md5
+ @sha1=self.class.sha1 unless @sha1
raise "@url.nil?" if @url.nil?
end
@@ -101,6 +102,22 @@ public
# The None part makes cmake use the environment's CFLAGS etc. settings
"-DCMAKE_INSTALL_PREFIX='#{prefix}' -DCMAKE_BUILD_TYPE=None"
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
def brew
@@ -110,14 +127,7 @@ public
tmp=nil
tgz=Pathname.new(fetch()).realpath
begin
- md5=`md5 -q "#{tgz}"`.strip
- 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
+ verify_download_integrity tgz
# we make an additional subdirectory so know exactly what we are
# recursively deleting later