brew/Library/Homebrew/api/source_download.rb
Mike McQuaid ed5805e50c
Add JSON API download strategy for download queue
This fixes the weird/broken existing behaviour which was incorrectly
creating symlinks at download time. It also defers much more logic to
the original code.

For clarity, rename the existing `API::Download` class to
`API::SourceDownload`.

While we're here:
- add a/improve the `download_type` method on all `Downloadable`
  subclasses to improve download queue output format
- move some logic to `RetryDownload`
2025-07-22 17:48:32 +01:00

57 lines
1.2 KiB
Ruby

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