Class: Bottle

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Downloadable
Defined in:
bottle.rb,
sorbet/rbi/dsl/bottle.rbi

Defined Under Namespace

Classes: Filename

Instance Attribute Summary collapse

Attributes included from Downloadable

#checksum, #mirrors, #phase

Instance Method Summary collapse

Methods included from Downloadable

#download_queue_message, #download_strategy, #downloaded!, #downloaded?, #downloading!, #extracting!, #fetched_size, #freeze, #initialize_dup, verification_cache, #verified!, #verifying!, #version

Methods included from Utils::Output::Mixin

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

Methods included from Context

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

Constructor Details

#initialize(formula, spec, tag = nil, name: nil, pkg_version: nil) ⇒ 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:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'bottle.rb', line 97

def initialize(formula, spec, tag = nil, name: nil, pkg_version: nil)
  super()

  resource_name = T.let(nil, T.nilable(String))
  if formula
    name = formula.name
    pkg_version = formula.pkg_version
  else
    raise ArgumentError, "Bottle name is required" if name.nil?
    raise ArgumentError, "Bottle version is required" if pkg_version.nil?

    resource_name = name
  end

  @name = T.let(name, String)
  @pkg_version = T.let(pkg_version, PkgVersion)
  @resource = T.let(Resource.new(resource_name), Resource)
  @resource.owner = formula if formula
  @spec = spec

  tag_spec = spec.tag_specification_for(Utils::Bottles.tag(tag))

  odie "#{@name} tag specification for tag #{tag} is nil" if tag_spec.nil?

  @tag = T.let(tag_spec.tag, Utils::Bottles::Tag)
  @cellar = T.let(tag_spec.cellar, T.any(String, Symbol))
  @rebuild = T.let(spec.rebuild, Integer)

  @resource.version(@pkg_version.to_s)
  @resource.checksum = tag_spec.checksum
  @manifest_checksum = T.let(tag_spec.manifest_checksum, T.nilable(Checksum))

  @fetch_tab_retried = T.let(false, T::Boolean)

  root_url(spec.root_url, spec.root_url_specs)
end

Instance Attribute Details

#cellar ⇒ String, Symbol (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:



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

def cellar
  @cellar
end

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



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

def name
  @name
end

#rebuild ⇒ Integer (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:



83
84
85
# File 'bottle.rb', line 83

def rebuild
  @rebuild
end

#resource ⇒ Resource (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 'bottle.rb', line 74

def resource
  @resource
end

#tag ⇒ Utils::Bottles::Tag (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 'bottle.rb', line 77

def tag
  @tag
end

Instance Method Details

#bottle_size ⇒ Integer?

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:



302
303
304
305
306
307
# File 'bottle.rb', line 302

def bottle_size
  resource = github_packages_manifest_resource
  return unless resource&.downloaded?

  resource.bottle_size
end

#built_cellar ⇒ Symbol, 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:



238
239
240
241
242
243
244
245
# File 'bottle.rb', line 238

def built_cellar
  tab = tab_attributes
  if tab["padded_prefix"] == true && (built_prefix = tab["built_prefix"])
    "#{built_prefix}/Cellar"
  else
    @spec.tag_to_cellar(@tag)
  end
end

#cached_download(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


10
# File 'sorbet/rbi/dsl/bottle.rbi', line 10

def cached_download(*args, &block); end

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



221
222
223
224
225
# File 'bottle.rb', line 221

def clear_cache
  @resource.clear_cache
  github_packages_manifest_resource&.clear_cache
  @fetch_tab_retried = false
end

#compatible_locations? ⇒ 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)


228
229
230
231
232
233
234
235
# File 'bottle.rb', line 228

def compatible_locations?
  return true if compatible_locations_from_tab?

  fetch_tab(quiet: true)
  compatible_locations_from_tab?
rescue DownloadError, Resource::BottleManifest::Error
  false
end

#discard_corrupt_cached_download(known_corrupt: false) ⇒ 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:

  • known_corrupt (Boolean) (defaults to: false)


197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'bottle.rb', line 197

def discard_corrupt_cached_download(known_corrupt: false)
  expected_checksum = resource.checksum
  return if expected_checksum.nil?
  return unless cached_download.file?

  unless known_corrupt
    # The remembered digest cannot be trusted here: the failed extraction
    # may mean the file was corrupted in place without changing the
    # metadata that keys the digest cache, so forget it and hash afresh.
    verification_cache = Downloadable.verification_cache
    verification_cache.invalidate!(cached_download)
    return if verification_cache.sha256(cached_download) == expected_checksum.hexdigest
  end

  opoo "Removing corrupt cached download: #{cached_download.basename}"
  clear_cache
end

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



488
# File 'bottle.rb', line 488

def download_queue_name = "#{name} (#{resource.version})"

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



485
# File 'bottle.rb', line 485

def download_queue_type = "Bottle"

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

Only reuse an immutable GitHub Packages blob after checking its contents.

Returns:

  • (Boolean)


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'bottle.rb', line 157

def downloaded_and_valid?
  return false unless cached_download.file?

  resource_checksum = resource.checksum
  return false if resource_checksum.nil?

  downloader = resource.downloader
  return false unless downloader.is_a?(CurlGitHubPackagesDownloadStrategy)
  return false unless downloader.immutable_bottle_blob?

  return false if downloader.bottle_blob_sha256 != resource_checksum.hexdigest

  verify_download_integrity(cached_download)
  true
rescue ChecksumMismatchError
  resource.clear_cache
  false
end

#downloader(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


13
# File 'sorbet/rbi/dsl/bottle.rbi', line 13

def downloader(*args, &block); end

#extract_snapshot(snapshot, cellar:, verbose: false) ⇒ 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:



414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'bottle.rb', line 414

def extract_snapshot(snapshot, cellar:, verbose: false)
  staging = snapshot.dirname/"unpacked"
  UnpackStrategy.detect(snapshot, prioritize_extension: true, temporary_directory: snapshot.dirname)
                .extract_nestedly(to: staging, basename: downloader.basename, prioritize_extension: true, verbose:)
  bottle_filename = filename
  rack = staging/bottle_filename.name
  keg = rack/bottle_filename.version.to_s
  if staging.children != [rack] || !rack.directory? || rack.symlink? ||
     rack.children != [keg] || !keg.directory? || keg.symlink?
    raise "Unexpected bottle contents: #{downloader.basename}"
  end

  destination = cellar/bottle_filename.name/bottle_filename.version.to_s
  # Publication runs in the parent, outside the extraction sandbox.
  Utils::Path.ensure_child_of!(cellar, destination,
                               message: "Bottle destination escapes the Cellar: #{destination}")
  raise "Bottle destination already exists: #{destination}" if destination.exist? || destination.symlink?

  destination.dirname.mkpath
  FileUtils.mv(keg, destination)
end

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



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'bottle.rb', line 141

def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
  resource.fetch(verify_download_integrity:, timeout:, quiet:)
rescue DownloadError
  # Use the default bottle domain as a fallback mirror
  raise unless @resource.url&.start_with?(Homebrew::EnvConfig.bottle_domain)
  raise unless Homebrew::EnvConfig.bottle_domain_custom?

  opoo "Bottle missing, falling back to the default domain..."
  root_url(HOMEBREW_BOTTLE_DEFAULT_DOMAIN)
  @github_packages_manifest_resource = T.let(nil, T.nilable(Resource::BottleManifest))
  fetch_tab
  retry
end

#fetch_tab(timeout: nil, quiet: false) ⇒ 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:

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


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'bottle.rb', line 271

def fetch_tab(timeout: nil, quiet: false)
  return unless (resource = github_packages_manifest_resource)

  begin
    # `$HOMEBREW_BOTTLE_DOMAIN` fallback is configured on the resource below.
    resource.fetch(timeout:, quiet:)
  rescue Resource::BottleManifest::Error, ChecksumMismatchError => e
    # Unlike invalid metadata, a manifest with the wrong checksum never
    # stays cached after the retry, as later reads would not check it.
    resource.clear_cache if !@fetch_tab_retried || e.is_a?(ChecksumMismatchError)
    raise if @fetch_tab_retried

    @fetch_tab_retried = true
    retry
  end
end

#filename ⇒ Filename

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:



334
# File 'bottle.rb', line 334

def filename = Filename.new(@name, @pkg_version, @tag, @spec.rebuild)

#github_packages_manifest_resource ⇒ Resource::BottleManifest?

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:



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'bottle.rb', line 437

def github_packages_manifest_resource
  # `$HOMEBREW_BOTTLE_DOMAIN` may be a legacy flat-file mirror, so its
  # bottle resource does not necessarily use the GitHub Packages strategy.
  custom_bottle_domain = Homebrew::EnvConfig.bottle_domain_custom? &&
                         root_url == Homebrew::EnvConfig.bottle_domain
  return if @resource.download_strategy != CurlGitHubPackagesDownloadStrategy && !custom_bottle_domain

  return @github_packages_manifest_resource if @github_packages_manifest_resource

  resource = Resource::BottleManifest.new(self)

  resource_version = @resource.version
  odie "resource version is nil" if resource_version.nil?

  version_rebuild = GitHubPackages.version_rebuild(resource_version, rebuild)
  resource.version(version_rebuild)

  image_name = GitHubPackages.image_formula_name(@name)
  # The JSON API supplies the digest of this bottle's own manifest; a
  # bottle block can only supply that of the index listing every bottle.
  manifest_sha256 = @manifest_checksum&.hexdigest || @spec.manifest_sha256
  # A digest names one immutable manifest; a tag can be moved to another.
  manifest_reference = if manifest_sha256
    "sha256:#{manifest_sha256}"
  else
    GitHubPackages.image_version_rebuild(version_rebuild)
  end
  manifest_path = "#{image_name}/manifests/#{manifest_reference}"
  resource.sha256(manifest_sha256) if manifest_sha256
  media_type = @manifest_checksum ? "manifest" : "index"
  resource.url(
    "#{root_url}/#{manifest_path}",
    using:   CurlGitHubPackagesDownloadStrategy,
    headers: ["Accept: application/vnd.oci.image.#{media_type}.v1+json"],
  )
  # Give a legacy mirror the first chance to serve the manifest. Many
  # contain only bottle archives, so retain GHCR as a fallback. By
  # contrast, `$HOMEBREW_ARTIFACT_DOMAIN` must provide an OCI registry
  # proxy for bottle blobs and manifests; the strategy rewrites the GHCR
  # URL for it.
  resource.mirror("#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/#{manifest_path}") if custom_bottle_domain
  T.cast(resource.downloader, CurlGitHubPackagesDownloadStrategy).resolved_basename =
    "#{name}-#{version_rebuild}.bottle_manifest.json"
  @github_packages_manifest_resource = T.let(resource, T.nilable(Resource::BottleManifest))
  resource
end

#installed_size ⇒ Integer?

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:



310
311
312
313
314
315
# File 'bottle.rb', line 310

def installed_size
  resource = github_packages_manifest_resource
  return unless resource&.downloaded?

  resource.installed_size
end

#path_exec_files ⇒ Array<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:



318
319
320
321
322
323
# File 'bottle.rb', line 318

def path_exec_files
  resource = github_packages_manifest_resource
  return unless resource&.downloaded?

  resource.path_exec_files
end

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



393
394
395
396
397
# File 'bottle.rb', line 393

def purge_staged_from_download_queue
  keg = staged_path_from_download_queue
  FileUtils.rm_rf([staged_path_from_download_queue_marker, keg])
  Utils::Path.rmdir_if_possible(keg.parent)
end

#sbom_supplement ⇒ Hash{String => 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.

Returns:



326
327
328
329
330
331
# File 'bottle.rb', line 326

def sbom_supplement
  resource = github_packages_manifest_resource
  return unless resource&.downloaded_and_valid?

  resource.sbom_supplement
end

#skip_relocation? ⇒ 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.

Does the bottle need to be relocated?

Returns:

  • (Boolean)


249
250
251
252
253
# File 'bottle.rb', line 249

def skip_relocation?
  attrs = tab_attributes
  tab = Tab.new(**attrs.transform_keys(&:to_sym)) unless attrs.empty?
  @spec.skip_relocation?(tag: @tag, tab:)
end

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



256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'bottle.rb', line 256

def stage
  with_corrupt_download_retry do
    with_verified_snapshot(cached_download) do |snapshot|
      extract_snapshot(snapshot, cellar: Pathname.pwd, verbose: verbose? && !downloader.quiet?)
    end
  end
rescue ChecksumMismatchError
  # The retry's fresh download can itself fail verification, raising from
  # inside the rescue clause above: remove the known-bad download so the
  # next attempt fetches it again.
  clear_cache
  raise
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:



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'bottle.rb', line 353

def stage_from_download_queue(download, pour:)
  return unless pour

  bottle_tmp_keg = staged_path_from_download_queue
  bottle_poured_file = staged_path_from_download_queue_marker

  # Stay quiet on the retry: the download queue is redrawing its own
  # progress lines while this runs in a worker thread.
  with_corrupt_download_retry(quiet: true) do
    # Never reuse a marker or keg already here: sandboxed build and
    # postinstall steps may have written them.
    purge_staged_from_download_queue

    with_verified_snapshot(download) do |snapshot|
      extract_snapshot(snapshot, cellar: HOMEBREW_TEMP_CELLAR)
    end

    # Create a separate file to mark a completed extraction. This avoids
    # a potential race condition if a user interrupts the install.
    # We use a symlink to easily check that both this extra status file
    # and the real extracted directory exist via `Pathname#exist?`.
    FileUtils.ln_s(bottle_tmp_keg, bottle_poured_file)
  # Catch any exception type here to clean up partial queued extractions.
  rescue Exception # rubocop:disable Lint/RescueException
    Utils::Interrupts.ignore { purge_staged_from_download_queue }
    raise
  end
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)


348
349
350
# File 'bottle.rb', line 348

def stage_from_download_queue?(_download, pour:)
  pour
end

#staged_from_download_queue? ⇒ 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.

Whether the download queue left a keg here that pour may move into the Cellar: the marker must point at the expected keg and the keg must be a real directory, so entries planted by other processes are ignored.

Returns:

  • (Boolean)


386
387
388
389
390
# File 'bottle.rb', line 386

def staged_from_download_queue?
  marker = staged_path_from_download_queue_marker
  keg = staged_path_from_download_queue
  marker.symlink? && marker.readlink == keg && !keg.symlink? && keg.directory?
end

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

Returns:



337
338
339
340
# File 'bottle.rb', line 337

def staged_path_from_download_queue
  bottle_filename = filename
  HOMEBREW_TEMP_CELLAR/bottle_filename.name/bottle_filename.version.to_s
end

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

Returns:



343
344
345
# File 'bottle.rb', line 343

def staged_path_from_download_queue_marker
  Pathname("#{staged_path_from_download_queue}.poured")
end

#tab_attributes ⇒ Hash{String => T.untyped}

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:



289
290
291
292
293
294
295
296
297
298
299
# File 'bottle.rb', line 289

def tab_attributes
  resource = github_packages_manifest_resource
  return {} unless resource&.downloaded?

  begin
    resource.tab
  rescue Resource::BottleManifest::Error, ChecksumMismatchError
    fetch_tab(quiet: true)
    resource.tab
  end
end

#total_size ⇒ Integer?

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:



216
217
218
# File 'bottle.rb', line 216

def total_size
  bottle_size || super
end

#url(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


16
# File 'sorbet/rbi/dsl/bottle.rbi', line 16

def url(*args, &block); end

#verify_download_integrity(*args, &block) ⇒ T.untyped

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:

  • args (T.untyped)
  • block (T.untyped)

Returns:

  • (T.untyped)


19
# File 'sorbet/rbi/dsl/bottle.rbi', line 19

def verify_download_integrity(*args, &block); end

#with_corrupt_download_retry(quiet: false, &_block) ⇒ 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.

Callers verify the cached download before consuming it. On failure, discard the cached file only when it is genuinely corrupt and retry once with a fresh download; a file that matches its checksum is kept and the original error re-raised.

Parameters:

  • quiet (Boolean) (defaults to: false)
  • _block (T.proc.void)


181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'bottle.rb', line 181

def with_corrupt_download_retry(quiet: false, &_block)
  yield
rescue => e
  # A checksum mismatch has already hashed the file and proven it
  # corrupt; only other failures, e.g. during extraction, need a fresh
  # hash to decide whether the file can be kept.
  discard_corrupt_cached_download(known_corrupt: e.is_a?(ChecksumMismatchError))
  raise if cached_download.exist?

  downloading!
  fetch(quiet:)
  extracting!
  yield
end

#with_verified_snapshot(download, &_block) ⇒ 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.

Verify a private copy of the download and hand it to the block, so the bytes extracted are the bytes verified even if the cached download is changed underneath by a process with write access to the cache.

Parameters:



403
404
405
406
407
408
409
410
411
# File 'bottle.rb', line 403

def with_verified_snapshot(download, &_block)
  HOMEBREW_TEMP_CELLAR.mkpath
  Dir.mktmpdir("verify-", HOMEBREW_TEMP_CELLAR) do |directory|
    snapshot = Pathname(directory)/download.basename
    FileUtils.copy_file(download, snapshot)
    verify_download_integrity(snapshot)
    yield snapshot
  end
end