Skip to content

Commit

Permalink
Implement Downloadable for more types.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Aug 14, 2024
1 parent 2c0b28c commit 5948aa0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ def run

sleep 0.05
rescue Interrupt
remaining_downloads.each do |_, future|
# FIXME: Implement cancellation of running downloads.
end

print "\n" * previous_pending_line_count
$stdout.flush
raise
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def run
end

if casks.any?

if args.dry_run?
if (casks_to_install = casks.reject(&:installed?).presence)
ohai "Would install #{::Utils.pluralize("cask", casks_to_install.count, include_count: true)}:"
Expand Down
8 changes: 0 additions & 8 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,6 @@ def stage
end
end

# Strategy for extracting local binary packages.
class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy
def initialize(path) # rubocop:disable Lint/MissingSuper
@cached_location = path
extend Pourable
end
end

# Strategy for downloading a Subversion repository.
#
# @api public
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/downloadable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def verify_download_integrity(filename)

sig { overridable.returns(String) }
def download_name
File.basename(determine_url.to_s)
@download_name ||= File.basename(determine_url.to_s)
end

private
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2773,10 +2773,12 @@ def on_system_blocks_exist?
).returns(Pathname)
}
def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
odeprecated "Formula#fetch", "Resource#fetch on Formula#resource"
active_spec.fetch(verify_download_integrity:, timeout:, quiet:)
end

def verify_download_integrity(filename)
odeprecated "Formula#verify_download_integrity", "Resource#verify_download_integrity on Formula#resource"
active_spec.verify_download_integrity(filename)
end

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1261,11 +1261,11 @@ def fetch

def downloader
if (bottle_path = formula.local_bottle_path)
LocalBottleDownloadStrategy.new(bottle_path)
Resource::Local.new(bottle_path)
elsif pour_bottle?
formula.bottle
else
formula
formula.resource
end
end

Expand Down
27 changes: 27 additions & 0 deletions Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,33 @@ def determine_url_mirrors
[*extra_urls, *super].uniq
end

# A local resource that doesn't need to be downloaded.
class Local < Resource
def initialize(path)
super(File.basename(path))
@path = path
end

sig { override.returns(Pathname) }
def cached_download
@path
end

sig { override.void }
def clear_cache; end

sig {
override.params(
verify_download_integrity: T::Boolean,
timeout: T.nilable(T.any(Integer, Float)),
quiet: T::Boolean,
).returns(Pathname)
}
def fetch(verify_download_integrity: true, timeout: nil, quiet: false)
cached_download
end
end

# A resource for a formula.
class Formula < Resource
sig { override.returns(String) }
Expand Down

0 comments on commit 5948aa0

Please sign in to comment.