
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`
54 lines
1.5 KiB
Ruby
54 lines
1.5 KiB
Ruby
# typed: strict
|
|
# frozen_string_literal: true
|
|
|
|
require "downloadable"
|
|
|
|
module Homebrew
|
|
module API
|
|
class JSONDownloadStrategy < AbstractDownloadStrategy
|
|
sig { params(url: String, name: String, version: T.any(NilClass, String, Version), meta: T.untyped).void }
|
|
def initialize(url, name, version, **meta)
|
|
super
|
|
@target = T.let(meta.fetch(:target), Pathname)
|
|
@stale_seconds = T.let(meta.fetch(:stale_seconds), Integer)
|
|
end
|
|
|
|
sig { override.params(timeout: T.nilable(T.any(Integer, Float))).returns(Pathname) }
|
|
def fetch(timeout: nil)
|
|
with_context quiet: quiet? do
|
|
Homebrew::API.fetch_json_api_file(url, target: cached_location, stale_seconds: meta.fetch(:stale_seconds))
|
|
end
|
|
cached_location
|
|
end
|
|
|
|
sig { override.returns(Pathname) }
|
|
def cached_location
|
|
meta.fetch(:target)
|
|
end
|
|
end
|
|
|
|
class JSONDownload
|
|
include Downloadable
|
|
|
|
sig { params(url: String, target: Pathname, stale_seconds: Integer).void }
|
|
def initialize(url, target:, stale_seconds:)
|
|
super()
|
|
@url = T.let(URL.new(url, using: API::JSONDownloadStrategy, target:, stale_seconds:), URL)
|
|
@target = target
|
|
@stale_seconds = stale_seconds
|
|
end
|
|
|
|
sig { override.returns(API::JSONDownloadStrategy) }
|
|
def downloader
|
|
T.cast(super, API::JSONDownloadStrategy)
|
|
end
|
|
|
|
sig { override.returns(String) }
|
|
def name = download_name
|
|
|
|
sig { override.returns(String) }
|
|
def download_type = "JSON API"
|
|
end
|
|
end
|
|
end
|