aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Good2010-03-23 19:56:20 -0500
committerAdam Vandenberg2010-03-23 21:23:25 -0700
commit9fbc26a39ff86f3a9b1ea0f79b502f5736a5119b (patch)
tree995c40b0b4ffcb1e77937bc7c21a1d25ab733b55
parent6586f89a29325d312a660cd80a3ea857c350e38a (diff)
downloadbrew-9fbc26a39ff86f3a9b1ea0f79b502f5736a5119b.tar.bz2
More effective use of incremental MD5 to eliminate loading entire tarball into memory
Signed-off-by: Adam Vandenberg <flangy@gmail.com>
-rw-r--r--Library/Homebrew/brew.h.rb2
-rw-r--r--Library/Homebrew/extend/pathname.rb8
-rw-r--r--Library/Homebrew/formula.rb9
3 files changed, 16 insertions, 3 deletions
diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb
index ff091fea3..78f84119f 100644
--- a/Library/Homebrew/brew.h.rb
+++ b/Library/Homebrew/brew.h.rb
@@ -52,7 +52,7 @@ def __make url, name
if strategy == CurlDownloadStrategy
d = strategy.new url, name, version, nil
the_tarball = d.fetch
- md5 = Digest::MD5.hexdigest(the_tarball.read)
+ md5 = the_tarball.md5
puts "MD5 is #{md5}"
else
puts "--cache requested, but we can only cache formulas that use Curl."
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 4416e0efe..e2489a51b 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -157,7 +157,13 @@ class Pathname
def md5
require 'digest'
- Digest::MD5.hexdigest(File.read(self))
+ incr_md5 = Digest::MD5.new
+ self.open('r') do |f|
+ f.each_line do |line|
+ incr_md5 << line
+ end
+ end
+ incr_md5.hexdigest
end
if '1.9' <= RUBY_VERSION
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 9f7137507..2605cd7a8 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -325,7 +325,14 @@ private
type ||= :md5
supplied=instance_variable_get("@#{type}")
type=type.to_s.upcase
- hash=Digest.const_get(type).hexdigest(fn.read)
+ hasher = Digest.const_get(type)
+
+ # Most are MD5 and it should be efficient.
+ if hasher == Digest::MD5
+ hash = fn.md5
+ else
+ hash = hasher.hexdigest(fn.read)
+ end
if supplied and not supplied.empty?
raise "#{type} mismatch\nExpected: #{hash}\nArchive: #{fn}" unless supplied.upcase == hash.upcase