Jack Nagel daef74aa27 Adjust semantics of Formula#fetch
It doesn't really make logical sense that this method returns both the
fetched path (or sometimes nil!) and the downloader, so just return the
path (again, or nil!) and callers that want the downloader can ask for
it separately.
2013-05-16 14:06:26 -05:00

42 lines
1.0 KiB
Ruby

require 'formula'
module Homebrew extend self
def fetch
raise FormulaUnspecifiedError if ARGV.named.empty?
if ARGV.include? '--deps'
bucket = []
ARGV.formulae.each do |f|
bucket << f
bucket.concat f.recursive_dependencies.map(&:to_formula)
end
bucket.uniq!
else
bucket = ARGV.formulae
end
puts "Fetching: #{bucket * ', '}" if bucket.size > 1
bucket.each { |f| fetch_formula(f) }
end
def already_fetched? f
f.cached_download.exist?
end
def fetch_formula f
f.cached_download.rmtree if already_fetched?(f) && ARGV.force?
download = f.fetch
# FIXME why are strategies returning different types?
return unless download.is_a? Pathname
puts "Downloaded to: #{download}" unless already_fetched?(f)
puts Checksum::TYPES.map { |t| "#{t.to_s.upcase}: #{download.send(t)}" }
f.verify_download_integrity(download)
rescue ChecksumMismatchError => e
Homebrew.failed = true
opoo "Formula reports different #{e.hash_type}: #{e.expected}"
end
end