Class: Cask::Download Private

Inherits:
Object
  • Object
show all
Includes:
Context
Defined in:
cask/download.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

A download corresponding to a Cask.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(cask, quarantine: nil) ⇒ Download

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new instance of Download.



17
18
19
20
# File 'cask/download.rb', line 17

def initialize(cask, quarantine: nil)
  @cask = cask
  @quarantine = quarantine
end

Instance Attribute Details

#caskObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



15
16
17
# File 'cask/download.rb', line 15

def cask
  @cask
end

Instance Method Details

#basenameObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



56
57
58
# File 'cask/download.rb', line 56

def basename
  downloader.basename
end

#cached_downloadObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



52
53
54
# File 'cask/download.rb', line 52

def cached_download
  downloader.cached_location
end

#clear_cacheObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



48
49
50
# File 'cask/download.rb', line 48

def clear_cache
  downloader.clear_cache
end

#downloaderObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



37
38
39
40
41
42
# File 'cask/download.rb', line 37

def downloader
  @downloader ||= begin
    strategy = DownloadStrategyDetector.detect(cask.url.to_s, cask.url.using)
    strategy.new(cask.url.to_s, cask.token, cask.version, cache: Cache.path, **cask.url.specs)
  end
end

#fetch(quiet: nil, verify_download_integrity: true, timeout: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'cask/download.rb', line 22

def fetch(quiet: nil, verify_download_integrity: true, timeout: nil)
  downloaded_path = begin
    downloader.shutup! if quiet
    downloader.fetch(timeout: timeout)
    downloader.cached_location
  rescue => e
    error = CaskError.new("Download failed on Cask '#{cask}' with message: #{e}")
    error.set_backtrace e.backtrace
    raise error
  end
  quarantine(downloaded_path)
  self.verify_download_integrity(downloaded_path) if verify_download_integrity
  downloaded_path
end

#time_file_size(timeout: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



44
45
46
# File 'cask/download.rb', line 44

def time_file_size(timeout: nil)
  downloader.resolved_time_file_size(timeout: timeout)
end

#verify_download_integrity(fn) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'cask/download.rb', line 60

def verify_download_integrity(fn)
  if @cask.sha256 == :no_check
    opoo "No checksum defined for cask '#{@cask}', skipping verification."
    return
  end

  begin
    ohai "Verifying checksum for cask '#{@cask}'" if verbose?
    fn.verify_checksum(@cask.sha256)
  rescue ChecksumMissingError
    opoo <<~EOS
      Cannot verify integrity of '#{fn.basename}'.
      No checksum was provided for this cask.
      For your reference, the checksum is:
        sha256 "#{fn.sha256}"
    EOS
  end
end