aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/fetch.rb
blob: 42a7199b5a1ce98dbff22a42a7429757b6ae5403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'formula'

# Downloads the tarballs for the given formulae to the Cache

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 << f.recursive_deps
      end

      bucket = bucket.flatten.uniq
    else
      bucket = ARGV.formulae
    end

    puts "Fetching: #{bucket * ', '}" if bucket.size > 1

    bucket.each do |f|
      already_downloaded = f.cached_download.exist?
      f.cached_download.rmtree if already_downloaded and ARGV.force?

      the_tarball, _ = f.fetch
      next unless the_tarball.kind_of? Pathname

      previous_md5 = f.active_spec.md5.to_s.downcase
      previous_sha1 = f.active_spec.sha1.to_s.downcase
      previous_sha2 = f.active_spec.sha256.to_s.downcase

      puts "Downloaded to: #{the_tarball}" unless already_downloaded
      puts "MD5:  #{the_tarball.md5}"
      puts "SHA1: #{the_tarball.sha1}"
      puts "SHA256: #{the_tarball.sha2}"

      begin
        f.verify_download_integrity the_tarball
      rescue ChecksumMismatchError => e
        opoo "Formula reports different #{e.hash_type}: #{e.expected}"
      end
    end
  end
end