More effective use of incremental MD5 to eliminate loading entire tarball into memory
Signed-off-by: Adam Vandenberg <flangy@gmail.com>
This commit is contained in:
		
							parent
							
								
									6586f89a29
								
							
						
					
					
						commit
						9fbc26a39f
					
				@ -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."
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user