Module: Downloadable Abstract

Overview

This module is abstract.

Subclasses must implement the abstract methods below.

Defined Under Namespace

Classes: VerificationCache

Instance Attribute Summary collapse

Class Method Summary collapse

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 Context

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

Instance Attribute Details

#checksumChecksum? (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.

Returns:



74
75
76
# File 'downloadable.rb', line 74

def checksum
  @checksum
end

#mirrorsArray<String> (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.

Returns:



77
78
79
# File 'downloadable.rb', line 77

def mirrors
  @mirrors
end

#phaseSymbol

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:



80
81
82
# File 'downloadable.rb', line 80

def phase
  @phase
end

#urlString, ... (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.

Returns:



71
72
73
# File 'downloadable.rb', line 71

def url
  @url
end

Class Method Details

.verification_cacheVerificationCache

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:



65
66
67
# File 'downloadable.rb', line 65

def verification_cache
  @verification_cache ||= T.let(VerificationCache.new, T.nilable(VerificationCache))
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:



149
150
151
# File 'downloadable.rb', line 149

def cached_download
  downloader.cached_location
end

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



154
155
156
# File 'downloadable.rb', line 154

def clear_cache
  downloader.clear_cache
end

#download_queue_messageString

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:



128
129
130
# File 'downloadable.rb', line 128

def download_queue_message
  "#{download_queue_type} #{download_queue_name}"
end

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



122
# File 'downloadable.rb', line 122

def download_queue_name = download_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.

This method is abstract.

Returns:



125
# File 'downloadable.rb', line 125

def download_queue_type; end

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



179
180
181
# File 'downloadable.rb', line 179

def download_strategy
  @download_strategy ||= T.must(determine_url).download_strategy
end

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



85
# File 'downloadable.rb', line 85

def downloaded! = (@phase = :downloaded)

#downloaded?Boolean

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:

  • (Boolean)


133
134
135
# File 'downloadable.rb', line 133

def downloaded?
  cached_download.exist?
end

#downloaded_and_valid?Boolean

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:

  • (Boolean)


138
139
140
141
142
143
144
145
146
# File 'downloadable.rb', line 138

def downloaded_and_valid?
  return false unless cached_download.file?
  return false if checksum.blank?

  with_context(quiet: true) { verify_download_integrity(cached_download) }
  true
rescue ChecksumMismatchError
  false
end

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



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'downloadable.rb', line 184

def downloader
  @downloader ||= begin
    primary_url, *mirrors = determine_url_mirrors
    raise ArgumentError, "attempted to use a `Downloadable` without a URL!" if primary_url.blank?

    download_strategy.new(primary_url, download_name, version,
                          mirrors:, cache:, **T.must(@url).specs).tap do |downloader|
      if downloader.is_a?(CurlDownloadStrategy) &&
         AbstractDownloadStrategy.expand_deferred_environment_for?(downloader)
        downloader.allow_deferred_environment_expansion!
      end
    end
  end
end

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



83
# File 'downloadable.rb', line 83

def downloading! = (@phase = :downloading)

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



91
# File 'downloadable.rb', line 91

def extracting! = (@phase = :extracting)

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



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'downloadable.rb', line 206

def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
  downloading!

  cache.mkpath

  begin
    downloader.quiet! if quiet
    downloader.fetch(timeout:)
  rescue ErrorDuringExecution, CurlDownloadStrategyError => e
    raise DownloadError.new(self, e)
  end

  downloaded!

  download = cached_download
  verify_download_integrity(download) if verify_download_integrity
  download
end

#fetched_sizeInteger?

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.

Total bytes downloaded if available.

Returns:



160
161
162
# File 'downloadable.rb', line 160

def fetched_size
  downloader.fetched_size
end

#freezeT.self_type

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:

  • (T.self_type)


114
115
116
117
118
119
# File 'downloadable.rb', line 114

def freeze
  @checksum.freeze
  @mirrors.freeze
  @version.freeze
  super
end

#initializevoid

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.



94
95
96
97
98
99
100
101
102
103
# File 'downloadable.rb', line 94

def initialize
  @url = T.let(nil, T.nilable(URL))
  @checksum = T.let(nil, T.nilable(Checksum))
  @mirrors = T.let([], T::Array[String])
  @version = T.let(nil, T.nilable(Version))
  @download_strategy = T.let(nil, T.nilable(T::Class[AbstractDownloadStrategy]))
  @downloader = T.let(nil, T.nilable(AbstractDownloadStrategy))
  @download_name = T.let(nil, T.nilable(String))
  @phase = T.let(:preparing, Symbol)
end

#initialize_dup(other) ⇒ 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
107
108
109
110
111
# File 'downloadable.rb', line 106

def initialize_dup(other)
  super
  @checksum = @checksum.dup
  @mirrors = @mirrors.dup
  @version = @version.dup
end

#stage_from_download_queue(_download, pour:) ⇒ 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:



231
# File 'downloadable.rb', line 231

def stage_from_download_queue(_download, pour:); end

#stage_from_download_queue?(_download, pour:) ⇒ Boolean

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:

Returns:

  • (Boolean)


226
227
228
# File 'downloadable.rb', line 226

def stage_from_download_queue?(_download, pour:)
  false
end

#total_sizeInteger?

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.

Total download size if available.

Returns:



166
167
168
# File 'downloadable.rb', line 166

def total_size
  @total_size ||= T.let(downloader.total_size, T.nilable(Integer))
end

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



89
# File 'downloadable.rb', line 89

def verified! = (@phase = :verified)

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



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'downloadable.rb', line 234

def verify_download_integrity(filename)
  verifying!

  if filename.file?
    Downloadable.verification_cache.verify(filename, checksum)
    verified!
  end
rescue ChecksumMissingError
  return if silence_checksum_missing_error?

  opoo <<~EOS
    Cannot verify integrity of '#{filename.basename}'.
    No checksum was provided.
    For your reference, the checksum is:
      sha256 "#{filename.sha256}"
  EOS
end

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



87
# File 'downloadable.rb', line 87

def verifying! = (@phase = :verifying)

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



171
172
173
174
175
176
# File 'downloadable.rb', line 171

def version
  return @version if @version && !@version.null?

  version = determine_url&.version
  version unless version&.null?
end