brew/Library/Homebrew/api/download.rb
Mike McQuaid 36c7f4950c
Optionally parallelise API file downloads
This assumes that all should be downloaded (at least once) on `brew`
commands being run.

Requires a certain amount of cleanup and refactoring around our API
handling and Tap migration methods (which were both weirdly placed and
in some cases broken).

Behaviour without `HOMEBREW_DOWNLOAD_CONCURRENCY` set should
be unchanged.
2025-07-18 15:01:34 +01:00

70 lines
1.5 KiB
Ruby

# typed: strict
# frozen_string_literal: true
require "downloadable"
module Homebrew
module API
class DownloadStrategy < CurlDownloadStrategy
sig { override.returns(Pathname) }
def symlink_location
cache/name
end
end
class Download
include Downloadable
sig {
params(
url: String,
checksum: T.nilable(Checksum),
mirrors: T::Array[String],
cache: T.nilable(Pathname),
require_checksum: T::Boolean,
).void
}
def initialize(url, checksum, mirrors: [], cache: nil, require_checksum: true)
super()
@url = T.let(URL.new(url, using: API::DownloadStrategy), URL)
@checksum = checksum
@mirrors = mirrors
@cache = cache
@require_checksum = require_checksum
end
sig { override.returns(API::DownloadStrategy) }
def downloader
T.cast(super, API::DownloadStrategy)
end
sig { override.returns(String) }
def name
download_name
end
sig { override.returns(String) }
def download_type
"API source"
end
sig { override.returns(Pathname) }
def cache
@cache || super
end
sig { returns(Pathname) }
def symlink_location
downloader.symlink_location
end
private
sig { override.returns(T::Boolean) }
def silence_checksum_missing_error?
!@require_checksum
end
end
end
end