Class: Homebrew::RetryableDownload Private

Inherits:
Object
  • Object
show all
Includes:
Downloadable
Defined in:
retryable_download.rb

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.

Instance Method Summary collapse

Methods included from Downloadable

#downloaded?, #freeze, #initialize_dup

Methods included from Context

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

Constructor Details

#initialize(downloadable, tries: 3) ⇒ void

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.

Parameters:

  • downloadable (Downloadable)
  • tries (Integer) (defaults to: 3)


22
23
24
25
26
27
28
# File 'retryable_download.rb', line 22

def initialize(downloadable, tries: 3)
  super()

  @downloadable = downloadable
  @try = 0
  @tries = tries
end

Instance Method Details

#cached_downloadPathname

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:



37
# File 'retryable_download.rb', line 37

def cached_download = downloadable.cached_download

#checksumChecksum?

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:



16
# File 'retryable_download.rb', line 16

def checksum = downloadable.checksum

#clear_cachevoid

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.

This method returns an undefined value.



40
# File 'retryable_download.rb', line 40

def clear_cache = downloadable.clear_cache

#download_nameString

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:



94
# File 'retryable_download.rb', line 94

def download_name = downloadable.download_name

#download_strategyT.class_of(AbstractDownloadStrategy)

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:



46
# File 'retryable_download.rb', line 46

def download_strategy = downloadable.download_strategy

#download_typeString

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:



34
# File 'retryable_download.rb', line 34

def download_type = downloadable.download_type

#downloaderAbstractDownloadStrategy

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.



49
# File 'retryable_download.rb', line 49

def downloader = downloadable.downloader

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

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.

Parameters:

  • verify_download_integrity (Boolean) (defaults to: true)
  • timeout (Integer, Float, nil) (defaults to: nil)
  • quiet (Boolean) (defaults to: false)

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'retryable_download.rb', line 58

def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
  @try += 1

  already_downloaded = downloadable.downloaded?

  download = downloadable.fetch(verify_download_integrity: false, timeout:, quiet:)

  return download unless download.file?

  unless quiet
    puts "Downloaded to: #{download}" unless already_downloaded
    puts "SHA256: #{download.sha256}"
  end

  downloadable.verify_download_integrity(download) if verify_download_integrity

  download
rescue DownloadError, ChecksumMismatchError
  tries_remaining = @tries - @try
  raise if tries_remaining.zero?

  wait = 2 ** @try
  unless quiet
    what = Utils.pluralize("tr", tries_remaining, plural: "ies", singular: "y")
    ohai "Retrying download in #{wait}s... (#{tries_remaining} #{what} left)"
  end
  sleep wait

  downloadable.clear_cache
  retry
end

#mirrorsArray<String>

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:



19
# File 'retryable_download.rb', line 19

def mirrors = downloadable.mirrors

#nameString

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:



31
# File 'retryable_download.rb', line 31

def name = downloadable.name

#urlURL?

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:



13
# File 'retryable_download.rb', line 13

def url = downloadable.url

#verify_download_integrity(filename) ⇒ void

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.

This method returns an undefined value.

Parameters:



91
# File 'retryable_download.rb', line 91

def verify_download_integrity(filename) = downloadable.verify_download_integrity(filename)

#versionVersion?

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:



43
# File 'retryable_download.rb', line 43

def version = downloadable.version