Skip to content

Commit

Permalink
Merge pull request Homebrew#10864 from reitermarkus/command-timeout
Browse files Browse the repository at this point in the history
Allow specifying timeouts for commands and downloads.
  • Loading branch information
MikeMcQuaid committed Mar 18, 2021
2 parents 3c3bf1c + 712a95f commit d55bdd3
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 94 deletions.
9 changes: 5 additions & 4 deletions Library/Homebrew/cask/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def initialize(cask, quarantine: nil)
@quarantine = quarantine
end

def fetch(verify_download_integrity: true)
def fetch(quiet: nil, verify_download_integrity: true, timeout: nil)
downloaded_path = begin
downloader.fetch
downloader.shutup! if quiet
downloader.fetch(timeout: timeout)
downloader.cached_location
rescue => e
error = CaskError.new("Download failed on Cask '#{cask}' with message: #{e}")
Expand All @@ -40,8 +41,8 @@ def downloader
end
end

def time_file_size
downloader.resolved_time_file_size
def time_file_size(timeout: nil)
downloader.resolved_time_file_size(timeout: timeout)
end

def clear_cache
Expand Down
17 changes: 10 additions & 7 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def self.caveats(cask)
EOS
end

def fetch
sig { params(quiet: T.nilable(T::Boolean), timeout: T.nilable(T.any(Integer, Float))).void }
def fetch(quiet: nil, timeout: nil)
odebug "Cask::Installer#fetch"

verify_has_sha if require_sha? && !force?
satisfy_dependencies

download
download(quiet: quiet, timeout: timeout)

satisfy_dependencies
end

def stage
Expand Down Expand Up @@ -162,9 +164,10 @@ def downloader
@downloader ||= Download.new(@cask, quarantine: quarantine?)
end

sig { returns(Pathname) }
def download
@download ||= downloader.fetch(verify_download_integrity: @verify_download_integrity)
sig { params(quiet: T.nilable(T::Boolean), timeout: T.nilable(T.any(Integer, Float))).returns(Pathname) }
def download(quiet: nil, timeout: nil)
@download ||= downloader.fetch(quiet: quiet, verify_download_integrity: @verify_download_integrity,
timeout: timeout)
end

def verify_has_sha
Expand All @@ -179,7 +182,7 @@ def verify_has_sha

def primary_container
@primary_container ||= begin
downloaded_path = download
downloaded_path = download(quiet: true)
UnpackStrategy.detect(downloaded_path, type: @cask.container&.type, merge_xattrs: true)
end
end
Expand Down

0 comments on commit d55bdd3

Please sign in to comment.