Port Homebrew::Cmd::FetchCmd
This commit is contained in:
parent
f83ba58f8d
commit
90cd9d2e0a
@ -1,19 +1,18 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "fetch"
|
||||
require "cli/parser"
|
||||
require "cask/download"
|
||||
|
||||
module Homebrew
|
||||
extend Fetch
|
||||
|
||||
module Cmd
|
||||
class FetchCmd < AbstractCommand
|
||||
include Fetch
|
||||
FETCH_MAX_TRIES = 5
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.fetch_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Download a bottle (if available) or source packages for <formula>e
|
||||
and binaries for <cask>s. For files, also print SHA-256 checksums.
|
||||
@ -67,11 +66,9 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :cask], min: 1
|
||||
end
|
||||
end
|
||||
|
||||
def self.fetch
|
||||
args = fetch_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
Formulary.enable_factory_cache!
|
||||
|
||||
bucket = if args.deps?
|
||||
@ -131,10 +128,10 @@ module Homebrew
|
||||
begin
|
||||
bottle.fetch_tab
|
||||
rescue DownloadError
|
||||
retry if retry_fetch?(bottle, args:)
|
||||
retry if retry_fetch?(bottle)
|
||||
raise
|
||||
end
|
||||
fetch_formula(bottle, args:)
|
||||
fetch_formula(bottle)
|
||||
rescue Interrupt
|
||||
raise
|
||||
rescue => e
|
||||
@ -150,14 +147,14 @@ module Homebrew
|
||||
|
||||
next if fetched_bottle
|
||||
|
||||
fetch_formula(formula, args:)
|
||||
fetch_formula(formula)
|
||||
|
||||
formula.resources.each do |r|
|
||||
fetch_resource(r, args:)
|
||||
r.patches.each { |p| fetch_patch(p, args:) if p.external? }
|
||||
fetch_resource(r)
|
||||
r.patches.each { |p| fetch_patch(p) if p.external? }
|
||||
end
|
||||
|
||||
formula.patchlist.each { |p| fetch_patch(p, args:) if p.external? }
|
||||
formula.patchlist.each { |p| fetch_patch(p) if p.external? }
|
||||
end
|
||||
end
|
||||
else
|
||||
@ -179,43 +176,43 @@ module Homebrew
|
||||
quarantine = true if quarantine.nil?
|
||||
|
||||
download = Cask::Download.new(cask, quarantine:)
|
||||
fetch_cask(download, args:)
|
||||
fetch_cask(download)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.fetch_resource(resource, args:)
|
||||
def fetch_resource(resource)
|
||||
puts "Resource: #{resource.name}"
|
||||
fetch_fetchable resource, args:
|
||||
fetch_fetchable resource
|
||||
rescue ChecksumMismatchError => e
|
||||
retry if retry_fetch?(resource, args:)
|
||||
retry if retry_fetch?(resource)
|
||||
opoo "Resource #{resource.name} reports different sha256: #{e.expected}"
|
||||
end
|
||||
|
||||
def self.fetch_formula(formula, args:)
|
||||
fetch_fetchable(formula, args:)
|
||||
def fetch_formula(formula)
|
||||
fetch_fetchable(formula)
|
||||
rescue ChecksumMismatchError => e
|
||||
retry if retry_fetch?(formula, args:)
|
||||
retry if retry_fetch?(formula)
|
||||
opoo "Formula reports different sha256: #{e.expected}"
|
||||
end
|
||||
|
||||
def self.fetch_cask(cask_download, args:)
|
||||
fetch_fetchable(cask_download, args:)
|
||||
def fetch_cask(cask_download)
|
||||
fetch_fetchable(cask_download)
|
||||
rescue ChecksumMismatchError => e
|
||||
retry if retry_fetch?(cask_download, args:)
|
||||
retry if retry_fetch?(cask_download)
|
||||
opoo "Cask reports different sha256: #{e.expected}"
|
||||
end
|
||||
|
||||
def self.fetch_patch(patch, args:)
|
||||
fetch_fetchable(patch, args:)
|
||||
def fetch_patch(patch)
|
||||
fetch_fetchable(patch)
|
||||
rescue ChecksumMismatchError => e
|
||||
opoo "Patch reports different sha256: #{e.expected}"
|
||||
Homebrew.failed = true
|
||||
end
|
||||
|
||||
def self.retry_fetch?(formula, args:)
|
||||
def retry_fetch?(formula)
|
||||
@fetch_tries ||= Hash.new { |h, k| h[k] = 1 }
|
||||
if args.retry? && (@fetch_tries[formula] < FETCH_MAX_TRIES)
|
||||
wait = 2 ** @fetch_tries[formula]
|
||||
@ -234,7 +231,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def self.fetch_fetchable(formula, args:)
|
||||
def fetch_fetchable(formula)
|
||||
formula.clear_cache if args.force?
|
||||
|
||||
already_fetched = formula.cached_download.exist?
|
||||
@ -242,7 +239,7 @@ module Homebrew
|
||||
begin
|
||||
download = formula.fetch(verify_download_integrity: false)
|
||||
rescue DownloadError
|
||||
retry if retry_fetch?(formula, args:)
|
||||
retry if retry_fetch?(formula)
|
||||
raise
|
||||
end
|
||||
|
||||
@ -253,4 +250,6 @@ module Homebrew
|
||||
|
||||
formula.verify_download_integrity(download)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/fetch"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe "brew fetch" do
|
||||
RSpec.describe Homebrew::Cmd::FetchCmd do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "downloads the Formula's URL", :integration_test do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user