2011-03-12 09:40:10 -08:00
|
|
|
require 'formula'
|
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2011-03-12 09:40:10 -08:00
|
|
|
def fetch
|
2012-02-04 00:01:29 -06:00
|
|
|
raise FormulaUnspecifiedError if ARGV.named.empty?
|
|
|
|
|
2011-04-14 14:57:21 -07:00
|
|
|
if ARGV.include? '--deps'
|
|
|
|
bucket = []
|
|
|
|
ARGV.formulae.each do |f|
|
|
|
|
bucket << f
|
2013-05-16 14:06:25 -05:00
|
|
|
bucket.concat f.recursive_dependencies.map(&:to_formula)
|
2011-04-14 14:57:21 -07:00
|
|
|
end
|
2013-05-16 14:06:25 -05:00
|
|
|
bucket.uniq!
|
2011-04-14 14:57:21 -07:00
|
|
|
else
|
|
|
|
bucket = ARGV.formulae
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Fetching: #{bucket * ', '}" if bucket.size > 1
|
2013-08-06 19:53:43 -07:00
|
|
|
bucket.each do |f|
|
2014-03-10 14:56:02 -05:00
|
|
|
if fetch_bottle?(f)
|
|
|
|
fetch_formula(f.bottle)
|
|
|
|
else
|
|
|
|
fetch_formula(f)
|
2014-03-13 19:51:23 -05:00
|
|
|
f.resources.each { |r| fetch_resource(r) }
|
|
|
|
f.patchlist.select(&:external?).each { |p| fetch_patch(p) }
|
2013-08-06 19:53:43 -07:00
|
|
|
end
|
|
|
|
end
|
2013-01-11 18:03:51 -06:00
|
|
|
end
|
2011-04-14 14:57:21 -07:00
|
|
|
|
2014-03-10 14:56:02 -05:00
|
|
|
def fetch_bottle? f
|
|
|
|
return true if ARGV.force_bottle? && f.bottle
|
|
|
|
return false unless f.bottle && f.pour_bottle?
|
|
|
|
return false if ARGV.build_from_source? || ARGV.build_bottle?
|
|
|
|
return false unless f.bottle.compatible_cellar?
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-08-06 19:53:43 -07:00
|
|
|
def fetch_resource r
|
|
|
|
puts "Resource: #{r.name}"
|
|
|
|
fetch_fetchable r
|
|
|
|
rescue ChecksumMismatchError => e
|
2014-03-08 17:21:37 +00:00
|
|
|
retry if retry_fetch? r
|
2013-08-06 19:53:43 -07:00
|
|
|
opoo "Resource #{r.name} reports different #{e.hash_type}: #{e.expected}"
|
|
|
|
end
|
|
|
|
|
2013-01-11 18:03:51 -06:00
|
|
|
def fetch_formula f
|
2013-08-06 19:53:43 -07:00
|
|
|
fetch_fetchable f
|
|
|
|
rescue ChecksumMismatchError => e
|
2014-03-01 12:28:45 +00:00
|
|
|
retry if retry_fetch? f
|
2013-08-06 19:53:43 -07:00
|
|
|
opoo "Formula reports different #{e.hash_type}: #{e.expected}"
|
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
def fetch_patch p
|
|
|
|
fetch_fetchable p
|
|
|
|
rescue ChecksumMismatchError => e
|
|
|
|
Homebrew.failed = true
|
|
|
|
opoo "Patch reports different #{e.hash_type}: #{e.expected}"
|
|
|
|
end
|
|
|
|
|
2013-08-06 19:53:43 -07:00
|
|
|
private
|
|
|
|
|
2014-03-01 12:28:45 +00:00
|
|
|
def retry_fetch? f
|
2014-08-22 22:55:10 -05:00
|
|
|
@fetch_failed ||= Set.new
|
|
|
|
if ARGV.include?("--retry") && @fetch_failed.add?(f.name)
|
|
|
|
ohai "Retrying download"
|
|
|
|
f.clear_cache
|
|
|
|
true
|
|
|
|
else
|
2014-03-01 12:28:45 +00:00
|
|
|
Homebrew.failed = true
|
2014-08-22 22:55:10 -05:00
|
|
|
false
|
2014-03-01 12:28:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-06 19:53:43 -07:00
|
|
|
def fetch_fetchable f
|
2013-10-31 14:28:49 -05:00
|
|
|
f.clear_cache if ARGV.force?
|
2013-10-31 14:28:49 -05:00
|
|
|
|
|
|
|
already_fetched = f.cached_download.exist?
|
2014-08-16 08:48:28 +01:00
|
|
|
|
|
|
|
begin
|
|
|
|
download = f.fetch
|
2014-08-22 22:55:10 -05:00
|
|
|
rescue DownloadError
|
2014-08-16 08:48:28 +01:00
|
|
|
retry if retry_fetch? f
|
2014-08-22 22:55:10 -05:00
|
|
|
raise
|
2014-08-16 08:48:28 +01:00
|
|
|
end
|
2011-03-12 09:40:10 -08:00
|
|
|
|
2013-05-16 14:06:26 -05:00
|
|
|
return unless download.file?
|
2011-03-12 09:40:10 -08:00
|
|
|
|
2013-10-31 14:28:49 -05:00
|
|
|
puts "Downloaded to: #{download}" unless already_fetched
|
2013-05-16 14:06:26 -05:00
|
|
|
puts Checksum::TYPES.map { |t| "#{t.to_s.upcase}: #{download.send(t)}" }
|
2013-01-11 18:03:51 -06:00
|
|
|
|
2013-05-16 14:06:26 -05:00
|
|
|
f.verify_download_integrity(download)
|
2011-03-12 09:40:10 -08:00
|
|
|
end
|
|
|
|
end
|