Class: Homebrew::RetryableDownload Private

Inherits:
Object
  • Object
show all
Includes:
Downloadable, Utils::Output::Mixin
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 Attribute Summary

Attributes included from Downloadable

#phase

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from Downloadable

#download_queue_message, #downloaded!, #downloaded?, #downloaded_and_valid?, #downloading!, #extracting!, #fetched_size, #freeze, #initialize_dup, #stage_from_download_queue, #stage_from_download_queue?, #total_size, #verified!, #verifying!

Methods included from Context

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

Constructor Details

#initialize(downloadable, tries:) ⇒ 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:



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

def initialize(downloadable, tries:)
  super()

  @downloadable = downloadable
  @try = T.let(0, Integer)
  @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:



38
# File 'retryable_download.rb', line 38

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:



17
# File 'retryable_download.rb', line 17

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.



41
# File 'retryable_download.rb', line 41

def clear_cache = downloadable.clear_cache

#download_queue_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:



32
# File 'retryable_download.rb', line 32

def download_queue_name = downloadable.download_queue_name

#download_queue_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:



35
# File 'retryable_download.rb', line 35

def download_queue_type = downloadable.download_queue_type

#download_strategyT::Class[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:



47
# File 'retryable_download.rb', line 47

def download_strategy = downloadable.download_strategy

#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.



50
# File 'retryable_download.rb', line 50

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:



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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'retryable_download.rb', line 59

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

  downloadable.downloading!

  already_downloaded = downloadable.downloaded?

  download = if downloadable.is_a?(Resource) && (resource = T.cast(downloadable, Resource))
    resource.fetch(verify_download_integrity: false, timeout:, quiet:, skip_patches: true)
  else
    downloadable.fetch(verify_download_integrity: false, timeout:, quiet:)
  end

  downloadable.downloaded!

  return download unless download.file?

  unless quiet
    puts "Downloaded to: #{download}" unless already_downloaded
    puts "SHA-256: #{download.sha256}"
  end

  json_download = downloadable.is_a?(API::JSONDownload)
  downloadable.verify_download_integrity(download) if verify_download_integrity && !json_download

  FileUtils.touch(download, mtime: Time.now) if json_download

  download
rescue DownloadError, ChecksumMismatchError, Resource::BottleManifest::Error => e
  tries_remaining = @tries - @try
  raise if tries_remaining.zero?

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

  # Preserve the partial `.incomplete` file on network errors so the next
  # attempt can resume via `--continue-at`. Clear the cache only when the
  # fully-downloaded file is known-bad (checksum or manifest mismatch).
  downloadable.clear_cache unless e.is_a?(DownloadError)
  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:



20
# File 'retryable_download.rb', line 20

def mirrors = downloadable.mirrors

#urlString, ...

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:



14
# File 'retryable_download.rb', line 14

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:



106
# File 'retryable_download.rb', line 106

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:



44
# File 'retryable_download.rb', line 44

def version = downloadable.version