Merge pull request #10922 from Rylan12/revert-timeout
Revert allowing timeouts for commands and downloads
This commit is contained in:
		
						commit
						6f9b4b8610
					
				@ -19,10 +19,9 @@ module Cask
 | 
			
		||||
      @quarantine = quarantine
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def fetch(quiet: nil, verify_download_integrity: true, timeout: nil)
 | 
			
		||||
    def fetch(verify_download_integrity: true)
 | 
			
		||||
      downloaded_path = begin
 | 
			
		||||
        downloader.shutup! if quiet
 | 
			
		||||
        downloader.fetch(timeout: timeout)
 | 
			
		||||
        downloader.fetch
 | 
			
		||||
        downloader.cached_location
 | 
			
		||||
      rescue => e
 | 
			
		||||
        error = CaskError.new("Download failed on Cask '#{cask}' with message: #{e}")
 | 
			
		||||
@ -41,8 +40,8 @@ module Cask
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def time_file_size(timeout: nil)
 | 
			
		||||
      downloader.resolved_time_file_size(timeout: timeout)
 | 
			
		||||
    def time_file_size
 | 
			
		||||
      downloader.resolved_time_file_size
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def clear_cache
 | 
			
		||||
 | 
			
		||||
@ -62,15 +62,13 @@ module Cask
 | 
			
		||||
      EOS
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    sig { params(quiet: T.nilable(T::Boolean), timeout: T.nilable(T.any(Integer, Float))).void }
 | 
			
		||||
    def fetch(quiet: nil, timeout: nil)
 | 
			
		||||
    def fetch
 | 
			
		||||
      odebug "Cask::Installer#fetch"
 | 
			
		||||
 | 
			
		||||
      verify_has_sha if require_sha? && !force?
 | 
			
		||||
 | 
			
		||||
      download(quiet: quiet, timeout: timeout)
 | 
			
		||||
 | 
			
		||||
      satisfy_dependencies
 | 
			
		||||
 | 
			
		||||
      download
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def stage
 | 
			
		||||
@ -164,10 +162,9 @@ module Cask
 | 
			
		||||
      @downloader ||= Download.new(@cask, quarantine: quarantine?)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
    sig { returns(Pathname) }
 | 
			
		||||
    def download
 | 
			
		||||
      @download ||= downloader.fetch(verify_download_integrity: @verify_download_integrity)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def verify_has_sha
 | 
			
		||||
@ -182,7 +179,7 @@ timeout: timeout)
 | 
			
		||||
 | 
			
		||||
    def primary_container
 | 
			
		||||
      @primary_container ||= begin
 | 
			
		||||
        downloaded_path = download(quiet: true)
 | 
			
		||||
        downloaded_path = download
 | 
			
		||||
        UnpackStrategy.detect(downloaded_path, type: @cask.container&.type, merge_xattrs: true)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -15,9 +15,6 @@ require "utils/curl"
 | 
			
		||||
 | 
			
		||||
require "github_packages"
 | 
			
		||||
 | 
			
		||||
require "extend/time"
 | 
			
		||||
using TimeRemaining
 | 
			
		||||
 | 
			
		||||
# @abstract Abstract superclass for all download strategies.
 | 
			
		||||
#
 | 
			
		||||
# @api private
 | 
			
		||||
@ -55,7 +52,7 @@ class AbstractDownloadStrategy
 | 
			
		||||
  # Download and cache the resource at {#cached_location}.
 | 
			
		||||
  #
 | 
			
		||||
  # @api public
 | 
			
		||||
  def fetch(timeout: nil); end
 | 
			
		||||
  def fetch; end
 | 
			
		||||
 | 
			
		||||
  # Disable any output during downloading.
 | 
			
		||||
  #
 | 
			
		||||
@ -179,20 +176,18 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
 | 
			
		||||
  # Download and cache the repository at {#cached_location}.
 | 
			
		||||
  #
 | 
			
		||||
  # @api public
 | 
			
		||||
  def fetch(timeout: nil)
 | 
			
		||||
    end_time = Time.now + timeout if timeout
 | 
			
		||||
 | 
			
		||||
  def fetch
 | 
			
		||||
    ohai "Cloning #{url}"
 | 
			
		||||
 | 
			
		||||
    if cached_location.exist? && repo_valid?
 | 
			
		||||
      puts "Updating #{cached_location}"
 | 
			
		||||
      update(timeout: timeout)
 | 
			
		||||
      update
 | 
			
		||||
    elsif cached_location.exist?
 | 
			
		||||
      puts "Removing invalid repository from cache"
 | 
			
		||||
      clear_cache
 | 
			
		||||
      clone_repo(timeout: end_time)
 | 
			
		||||
      clone_repo
 | 
			
		||||
    else
 | 
			
		||||
      clone_repo(timeout: end_time)
 | 
			
		||||
      clone_repo
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    version.update_commit(last_commit) if head?
 | 
			
		||||
@ -237,11 +232,9 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
 | 
			
		||||
    raise NotImplementedError
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil); end
 | 
			
		||||
  def clone_repo; end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update(timeout: nil); end
 | 
			
		||||
  def update; end
 | 
			
		||||
 | 
			
		||||
  def current_revision; end
 | 
			
		||||
 | 
			
		||||
@ -360,9 +353,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
  # Download and cache the file at {#cached_location}.
 | 
			
		||||
  #
 | 
			
		||||
  # @api public
 | 
			
		||||
  def fetch(timeout: nil)
 | 
			
		||||
    end_time = Time.now + timeout if timeout
 | 
			
		||||
 | 
			
		||||
  def fetch
 | 
			
		||||
    download_lock = LockFile.new(temporary_path.basename)
 | 
			
		||||
    download_lock.lock
 | 
			
		||||
 | 
			
		||||
@ -373,7 +364,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
 | 
			
		||||
      ohai "Downloading #{url}"
 | 
			
		||||
 | 
			
		||||
      resolved_url, _, url_time, = resolve_url_basename_time_file_size(url, timeout: end_time&.remaining!)
 | 
			
		||||
      resolved_url, _, url_time, = resolve_url_basename_time_file_size(url)
 | 
			
		||||
 | 
			
		||||
      fresh = if cached_location.exist? && url_time
 | 
			
		||||
        url_time <= cached_location.mtime
 | 
			
		||||
@ -387,7 +378,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
        puts "Already downloaded: #{cached_location}"
 | 
			
		||||
      else
 | 
			
		||||
        begin
 | 
			
		||||
          _fetch(url: url, resolved_url: resolved_url, timeout: end_time&.remaining!)
 | 
			
		||||
          _fetch(url: url, resolved_url: resolved_url)
 | 
			
		||||
        rescue ErrorDuringExecution
 | 
			
		||||
          raise CurlDownloadStrategyError, url
 | 
			
		||||
        end
 | 
			
		||||
@ -404,8 +395,6 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
 | 
			
		||||
      puts "Trying a mirror..."
 | 
			
		||||
      retry
 | 
			
		||||
    rescue Timeout::Error => e
 | 
			
		||||
      raise Timeout::Error, "Timed out downloading #{self.url}: #{e}"
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    download_lock&.unlock
 | 
			
		||||
@ -417,19 +406,19 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
    rm_rf(temporary_path)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def resolved_time_file_size(timeout: nil)
 | 
			
		||||
    _, _, time, file_size = resolve_url_basename_time_file_size(url, timeout: timeout)
 | 
			
		||||
  def resolved_time_file_size
 | 
			
		||||
    _, _, time, file_size = resolve_url_basename_time_file_size(url)
 | 
			
		||||
    [time, file_size]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def resolved_url_and_basename(timeout: nil)
 | 
			
		||||
    resolved_url, basename, = resolve_url_basename_time_file_size(url, timeout: nil)
 | 
			
		||||
  def resolved_url_and_basename
 | 
			
		||||
    resolved_url, basename, = resolve_url_basename_time_file_size(url)
 | 
			
		||||
    [resolved_url, basename]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def resolve_url_basename_time_file_size(url, timeout: nil)
 | 
			
		||||
  def resolve_url_basename_time_file_size(url)
 | 
			
		||||
    @resolved_info_cache ||= {}
 | 
			
		||||
    return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
 | 
			
		||||
 | 
			
		||||
@ -437,7 +426,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
      url = url.sub(%r{^((ht|f)tps?://)?}, "#{domain.chomp("/")}/")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s, timeout: timeout)
 | 
			
		||||
    out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s)
 | 
			
		||||
 | 
			
		||||
    lines = status.success? ? out.lines.map(&:chomp) : []
 | 
			
		||||
 | 
			
		||||
@ -496,7 +485,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
    @resolved_info_cache[url] = [redirect_url, basename, time, file_size]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def _fetch(url:, resolved_url:, timeout:)
 | 
			
		||||
  def _fetch(url:, resolved_url:)
 | 
			
		||||
    ohai "Downloading from #{resolved_url}" if url != resolved_url
 | 
			
		||||
 | 
			
		||||
    if Homebrew::EnvConfig.no_insecure_redirect? &&
 | 
			
		||||
@ -505,7 +494,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
 | 
			
		||||
      raise CurlDownloadStrategyError, url
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    curl_download resolved_url, to: temporary_path, timeout: timeout
 | 
			
		||||
    curl_download resolved_url, to: temporary_path
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Curl options to be always passed to curl,
 | 
			
		||||
@ -578,9 +567,9 @@ class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
 | 
			
		||||
    @combined_mirrors = [*@mirrors, *backup_mirrors]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def resolve_url_basename_time_file_size(url, timeout: nil)
 | 
			
		||||
  def resolve_url_basename_time_file_size(url)
 | 
			
		||||
    if url == self.url
 | 
			
		||||
      super("#{apache_mirrors["preferred"]}#{apache_mirrors["path_info"]}", timeout: timeout)
 | 
			
		||||
      super("#{apache_mirrors["preferred"]}#{apache_mirrors["path_info"]}")
 | 
			
		||||
    else
 | 
			
		||||
      super
 | 
			
		||||
    end
 | 
			
		||||
@ -603,7 +592,7 @@ end
 | 
			
		||||
class CurlPostDownloadStrategy < CurlDownloadStrategy
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def _fetch(url:, resolved_url:, timeout:)
 | 
			
		||||
  def _fetch(url:, resolved_url:)
 | 
			
		||||
    args = if meta.key?(:data)
 | 
			
		||||
      escape_data = ->(d) { ["-d", URI.encode_www_form([d])] }
 | 
			
		||||
      [url, *meta[:data].flat_map(&escape_data)]
 | 
			
		||||
@ -612,7 +601,7 @@ class CurlPostDownloadStrategy < CurlDownloadStrategy
 | 
			
		||||
      query.nil? ? [url, "-X", "POST"] : [url, "-d", query]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    curl_download(*args, to: temporary_path, timeout: timeout)
 | 
			
		||||
    curl_download(*args, to: temporary_path)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -652,7 +641,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
  # Download and cache the repository at {#cached_location}.
 | 
			
		||||
  #
 | 
			
		||||
  # @api public
 | 
			
		||||
  def fetch(timeout: nil)
 | 
			
		||||
  def fetch
 | 
			
		||||
    if @url.chomp("/") != repo_url || !silent_command("svn", args: ["switch", @url, cached_location]).success?
 | 
			
		||||
      clear_cache
 | 
			
		||||
    end
 | 
			
		||||
@ -693,11 +682,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig {
 | 
			
		||||
    params(target: Pathname, url: String, revision: T.nilable(String), ignore_externals: T::Boolean,
 | 
			
		||||
   timeout: T.nilable(Time)).void
 | 
			
		||||
  }
 | 
			
		||||
  def fetch_repo(target, url, revision = nil, ignore_externals: false, timeout: nil)
 | 
			
		||||
  def fetch_repo(target, url, revision = nil, ignore_externals: false)
 | 
			
		||||
    # Use "svn update" when the repository already exists locally.
 | 
			
		||||
    # This saves on bandwidth and will have a similar effect to verifying the
 | 
			
		||||
    # cache as it will make any changes to get the right revision.
 | 
			
		||||
@ -717,9 +702,9 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if target.directory?
 | 
			
		||||
      command! "svn", args: ["update", *args], chdir: target.to_s, timeout: timeout&.remaining
 | 
			
		||||
      command!("svn", args: ["update", *args], chdir: target.to_s)
 | 
			
		||||
    else
 | 
			
		||||
      command! "svn", args: ["checkout", url, target, *args], timeout: timeout&.remaining
 | 
			
		||||
      command!("svn", args: ["checkout", url, target, *args])
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -732,22 +717,20 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    (cached_location/".svn").directory?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil)
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    case @ref_type
 | 
			
		||||
    when :revision
 | 
			
		||||
      fetch_repo cached_location, @url, @ref, timeout: timeout
 | 
			
		||||
      fetch_repo cached_location, @url, @ref
 | 
			
		||||
    when :revisions
 | 
			
		||||
      # nil is OK for main_revision, as fetch_repo will then get latest
 | 
			
		||||
      main_revision = @ref[:trunk]
 | 
			
		||||
      fetch_repo cached_location, @url, main_revision, ignore_externals: true, timeout: timeout
 | 
			
		||||
      fetch_repo cached_location, @url, main_revision, ignore_externals: true
 | 
			
		||||
 | 
			
		||||
      externals do |external_name, external_url|
 | 
			
		||||
        fetch_repo cached_location/external_name, external_url, @ref[external_name], ignore_externals: true,
 | 
			
		||||
                                                                                     timeout:          timeout
 | 
			
		||||
        fetch_repo cached_location/external_name, external_url, @ref[external_name], ignore_externals: true
 | 
			
		||||
      end
 | 
			
		||||
    else
 | 
			
		||||
      fetch_repo cached_location, @url, timeout: timeout
 | 
			
		||||
      fetch_repo cached_location, @url
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  alias update clone_repo
 | 
			
		||||
@ -796,13 +779,12 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    0
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update(timeout: nil)
 | 
			
		||||
  def update
 | 
			
		||||
    config_repo
 | 
			
		||||
    update_repo(timeout: timeout)
 | 
			
		||||
    checkout(timeout: timeout)
 | 
			
		||||
    update_repo
 | 
			
		||||
    checkout
 | 
			
		||||
    reset
 | 
			
		||||
    update_submodules(timeout: timeout) if submodules?
 | 
			
		||||
    update_submodules if submodules?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def shallow_clone?
 | 
			
		||||
@ -863,7 +845,6 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { void }
 | 
			
		||||
  def config_repo
 | 
			
		||||
    command! "git",
 | 
			
		||||
             args:  ["config", "remote.origin.url", @url],
 | 
			
		||||
@ -876,42 +857,35 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update_repo(timeout: nil)
 | 
			
		||||
  def update_repo
 | 
			
		||||
    return if @ref_type != :branch && ref?
 | 
			
		||||
 | 
			
		||||
    if !shallow_clone? && shallow_dir?
 | 
			
		||||
      command! "git",
 | 
			
		||||
               args:  ["fetch", "origin", "--unshallow"],
 | 
			
		||||
               chdir:   cached_location,
 | 
			
		||||
               timeout: timeout&.remaining
 | 
			
		||||
               chdir: cached_location
 | 
			
		||||
    else
 | 
			
		||||
      command! "git",
 | 
			
		||||
               args:  ["fetch", "origin"],
 | 
			
		||||
               chdir:   cached_location,
 | 
			
		||||
               timeout: timeout&.remaining
 | 
			
		||||
               chdir: cached_location
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil)
 | 
			
		||||
    command! "git", args: clone_args, timeout: timeout&.remaining
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    command! "git", args: clone_args
 | 
			
		||||
 | 
			
		||||
    command! "git",
 | 
			
		||||
             args:  ["config", "homebrew.cacheversion", cache_version],
 | 
			
		||||
             chdir:   cached_location,
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
    checkout(timeout: timeout)
 | 
			
		||||
    update_submodules(timeout: timeout) if submodules?
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
    checkout
 | 
			
		||||
    update_submodules if submodules?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def checkout(timeout: nil)
 | 
			
		||||
  def checkout
 | 
			
		||||
    ohai "Checking out #{@ref_type} #{@ref}" if @ref_type && @ref
 | 
			
		||||
    command! "git", args: ["checkout", "-f", @ref, "--"], chdir: cached_location, timeout: timeout&.remaining
 | 
			
		||||
    command! "git", args: ["checkout", "-f", @ref, "--"], chdir: cached_location
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { void }
 | 
			
		||||
  def reset
 | 
			
		||||
    ref = case @ref_type
 | 
			
		||||
    when :branch
 | 
			
		||||
@ -925,16 +899,13 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update_submodules(timeout: nil)
 | 
			
		||||
  def update_submodules
 | 
			
		||||
    command! "git",
 | 
			
		||||
             args:  ["submodule", "foreach", "--recursive", "git submodule sync"],
 | 
			
		||||
             chdir:   cached_location,
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
    command! "git",
 | 
			
		||||
             args:  ["submodule", "update", "--init", "--recursive"],
 | 
			
		||||
             chdir:   cached_location,
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
    fix_absolute_submodule_gitdir_references!
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -1086,23 +1057,19 @@ class CVSDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    "-Q" unless verbose?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil)
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    # Login is only needed (and allowed) with pserver; skip for anoncvs.
 | 
			
		||||
    command! "cvs", args: [*quiet_flag, "-d", @url, "login"], timeout: timeout&.remaining if @url.include? "pserver"
 | 
			
		||||
    command! "cvs", args: [*quiet_flag, "-d", @url, "login"] if @url.include? "pserver"
 | 
			
		||||
 | 
			
		||||
    command! "cvs",
 | 
			
		||||
             args:  [*quiet_flag, "-d", @url, "checkout", "-d", cached_location.basename, @module],
 | 
			
		||||
             chdir:   cached_location.dirname,
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
             chdir: cached_location.dirname
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update(timeout: nil)
 | 
			
		||||
  def update
 | 
			
		||||
    command! "cvs",
 | 
			
		||||
             args:  [*quiet_flag, "update"],
 | 
			
		||||
             chdir:   cached_location,
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def split_url(in_url)
 | 
			
		||||
@ -1154,14 +1121,12 @@ class MercurialDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    (cached_location/".hg").directory?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil)
 | 
			
		||||
    command! "hg", args: ["clone", @url, cached_location], timeout: timeout&.remaining
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    command! "hg", args: ["clone", @url, cached_location]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update(timeout: nil)
 | 
			
		||||
    command! "hg", args: ["--cwd", cached_location, "pull", "--update"], timeout: timeout&.remaining
 | 
			
		||||
  def update
 | 
			
		||||
    command! "hg", args: ["--cwd", cached_location, "pull", "--update"]
 | 
			
		||||
 | 
			
		||||
    update_args = if @ref_type && @ref
 | 
			
		||||
      ohai "Checking out #{@ref_type} #{@ref}"
 | 
			
		||||
@ -1170,7 +1135,7 @@ class MercurialDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
      ["--clean"]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    command! "hg", args: ["--cwd", cached_location, "update", *update_args], timeout: timeout&.remaining
 | 
			
		||||
    command! "hg", args: ["--cwd", cached_location, "update", *update_args]
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1219,20 +1184,16 @@ class BazaarDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    (cached_location/".bzr").directory?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil)
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    # "lightweight" means history-less
 | 
			
		||||
    command! "bzr",
 | 
			
		||||
             args:    ["checkout", "--lightweight", @url, cached_location],
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
             args: ["checkout", "--lightweight", @url, cached_location]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update(timeout: nil)
 | 
			
		||||
  def update
 | 
			
		||||
    command! "bzr",
 | 
			
		||||
             args:  ["update"],
 | 
			
		||||
             chdir:   cached_location,
 | 
			
		||||
             timeout: timeout&.remaining
 | 
			
		||||
             chdir: cached_location
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1275,14 +1236,12 @@ class FossilDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
    "fossil"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def clone_repo(timeout: nil)
 | 
			
		||||
    silent_command! "fossil", args: ["clone", @url, cached_location], timeout: timeout&.remaining
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    silent_command!("fossil", args: ["clone", @url, cached_location])
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(timeout: T.nilable(Time)).void }
 | 
			
		||||
  def update(timeout: nil)
 | 
			
		||||
    silent_command! "fossil", args: ["pull", "-R", cached_location], timeout: timeout&.remaining
 | 
			
		||||
  def update
 | 
			
		||||
    silent_command!("fossil", args: ["pull", "-R", cached_location])
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,18 +0,0 @@
 | 
			
		||||
# typed: false
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
module TimeRemaining
 | 
			
		||||
  refine Time do
 | 
			
		||||
    def remaining
 | 
			
		||||
      [0, self - Time.now].max
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def remaining!
 | 
			
		||||
      r = remaining
 | 
			
		||||
 | 
			
		||||
      raise Timeout::Error if r <= 0
 | 
			
		||||
 | 
			
		||||
      r
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -28,16 +28,4 @@ when "HashValidator"
 | 
			
		||||
      def assert_valid_keys!(*valid_keys); end
 | 
			
		||||
    end
 | 
			
		||||
  RUBY
 | 
			
		||||
when "TimeRemaining"
 | 
			
		||||
  puts <<-RUBY
 | 
			
		||||
    # typed: strict
 | 
			
		||||
 | 
			
		||||
    class ::Time
 | 
			
		||||
      sig { returns(T.any(Integer, Float)) }
 | 
			
		||||
      def remaining; end
 | 
			
		||||
 | 
			
		||||
      sig { returns(T.any(Integer, Float)) }
 | 
			
		||||
      def remaining!; end
 | 
			
		||||
    end
 | 
			
		||||
  RUBY
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -10,15 +10,13 @@ require "extend/io"
 | 
			
		||||
require "extend/predicable"
 | 
			
		||||
require "extend/hash_validator"
 | 
			
		||||
 | 
			
		||||
require "extend/time"
 | 
			
		||||
 | 
			
		||||
# Class for running sub-processes and capturing their output and exit status.
 | 
			
		||||
#
 | 
			
		||||
# @api private
 | 
			
		||||
class SystemCommand
 | 
			
		||||
  extend T::Sig
 | 
			
		||||
 | 
			
		||||
  using TimeRemaining
 | 
			
		||||
  using HashValidator
 | 
			
		||||
 | 
			
		||||
  # Helper functions for calling {SystemCommand.run}.
 | 
			
		||||
  module Mixin
 | 
			
		||||
@ -80,24 +78,10 @@ class SystemCommand
 | 
			
		||||
      verbose:      T.nilable(T::Boolean),
 | 
			
		||||
      secrets:      T.any(String, T::Array[String]),
 | 
			
		||||
      chdir:        T.any(String, Pathname),
 | 
			
		||||
      timeout:      T.nilable(T.any(Integer, Float)),
 | 
			
		||||
    ).void
 | 
			
		||||
  }
 | 
			
		||||
  def initialize(
 | 
			
		||||
    executable,
 | 
			
		||||
    args: [],
 | 
			
		||||
    sudo: false,
 | 
			
		||||
    env: {},
 | 
			
		||||
    input: [],
 | 
			
		||||
    must_succeed: false,
 | 
			
		||||
    print_stdout: false,
 | 
			
		||||
    print_stderr: true,
 | 
			
		||||
    debug: nil,
 | 
			
		||||
    verbose: false,
 | 
			
		||||
    secrets: [],
 | 
			
		||||
    chdir: T.unsafe(nil),
 | 
			
		||||
    timeout: nil
 | 
			
		||||
  )
 | 
			
		||||
  def initialize(executable, args: [], sudo: false, env: {}, input: [], must_succeed: false,
 | 
			
		||||
                 print_stdout: false, print_stderr: true, debug: nil, verbose: nil, secrets: [], chdir: T.unsafe(nil))
 | 
			
		||||
    require "extend/ENV"
 | 
			
		||||
    @executable = executable
 | 
			
		||||
    @args = args
 | 
			
		||||
@ -116,7 +100,6 @@ class SystemCommand
 | 
			
		||||
    @verbose = verbose
 | 
			
		||||
    @secrets = (Array(secrets) + ENV.sensitive_environment.values).uniq
 | 
			
		||||
    @chdir = chdir
 | 
			
		||||
    @timeout = timeout
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { returns(T::Array[String]) }
 | 
			
		||||
@ -214,14 +197,10 @@ class SystemCommand
 | 
			
		||||
 | 
			
		||||
  sig { params(sources: T::Array[IO], _block: T.proc.params(type: Symbol, line: String).void).void }
 | 
			
		||||
  def each_line_from(sources, &_block)
 | 
			
		||||
    end_time = Time.now + @timeout if @timeout
 | 
			
		||||
 | 
			
		||||
    loop do
 | 
			
		||||
      select_timeout = end_time&.remaining!
 | 
			
		||||
      readable_sources, = IO.select(sources, [], [], select_timeout)
 | 
			
		||||
      raise Timeout::Error if readable_sources.nil?
 | 
			
		||||
      readable_sources, = IO.select(sources)
 | 
			
		||||
 | 
			
		||||
      readable_sources = readable_sources.reject(&:eof?)
 | 
			
		||||
      readable_sources = T.must(readable_sources).reject(&:eof?)
 | 
			
		||||
 | 
			
		||||
      break if readable_sources.empty?
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,15 +3,11 @@
 | 
			
		||||
 | 
			
		||||
require "open3"
 | 
			
		||||
 | 
			
		||||
require "extend/time"
 | 
			
		||||
 | 
			
		||||
module Utils
 | 
			
		||||
  # Helper function for interacting with `curl`.
 | 
			
		||||
  #
 | 
			
		||||
  # @api private
 | 
			
		||||
  module Curl
 | 
			
		||||
    using TimeRemaining
 | 
			
		||||
 | 
			
		||||
    module_function
 | 
			
		||||
 | 
			
		||||
    def curl_executable
 | 
			
		||||
@ -53,20 +49,14 @@ module Utils
 | 
			
		||||
        args << "--silent" unless $stdout.tty?
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      args << "--connect-timeout" << connect_timeout.round(3) if options[:connect_timeout]
 | 
			
		||||
      args << "--max-time" << max_time.round(3) if options[:max_time]
 | 
			
		||||
      args << "--retry" << Homebrew::EnvConfig.curl_retries unless options[:retry] == false
 | 
			
		||||
      args << "--retry-max-time" << retry_max_time.round if options[:retry_max_time]
 | 
			
		||||
 | 
			
		||||
      args + extra_args
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def curl_with_workarounds(
 | 
			
		||||
      *args,
 | 
			
		||||
      secrets: nil, print_stdout: nil, print_stderr: nil, debug: nil, verbose: nil, env: {}, timeout: nil, **options
 | 
			
		||||
      *args, secrets: nil, print_stdout: nil, print_stderr: nil, debug: nil, verbose: nil, env: {}, **options
 | 
			
		||||
    )
 | 
			
		||||
      end_time = Time.now + timeout if timeout
 | 
			
		||||
 | 
			
		||||
      command_options = {
 | 
			
		||||
        secrets:      secrets,
 | 
			
		||||
        print_stdout: print_stdout,
 | 
			
		||||
@ -80,20 +70,12 @@ module Utils
 | 
			
		||||
      result = system_command curl_executable,
 | 
			
		||||
                              args: curl_args(*args, **options),
 | 
			
		||||
                              env:  { "SSL_CERT_FILE" => nil }.merge(env),
 | 
			
		||||
                              timeout: end_time&.remaining,
 | 
			
		||||
                              **command_options
 | 
			
		||||
 | 
			
		||||
      return result if result.success? || !args.exclude?("--http1.1")
 | 
			
		||||
 | 
			
		||||
      raise Timeout::Error, result.stderr.lines.last.chomp if timeout && result.status.exitstatus == 28
 | 
			
		||||
 | 
			
		||||
      # Error in the HTTP2 framing layer
 | 
			
		||||
      if result.status.exitstatus == 16
 | 
			
		||||
        return curl_with_workarounds(
 | 
			
		||||
          *args, "--http1.1",
 | 
			
		||||
          timeout: end_time&.remaining, **command_options, **options
 | 
			
		||||
        )
 | 
			
		||||
      end
 | 
			
		||||
      return curl_with_workarounds(*args, "--http1.1", **command_options, **options) if result.status.exitstatus == 16
 | 
			
		||||
 | 
			
		||||
      # This is a workaround for https://github.com/curl/curl/issues/1618.
 | 
			
		||||
      if result.status.exitstatus == 56 # Unexpected EOF
 | 
			
		||||
@ -176,12 +158,9 @@ module Utils
 | 
			
		||||
      hash_needed = false
 | 
			
		||||
      if url != secure_url
 | 
			
		||||
        user_agents.each do |user_agent|
 | 
			
		||||
          secure_details = begin
 | 
			
		||||
          secure_details =
 | 
			
		||||
            curl_http_content_headers_and_checksum(secure_url, specs: specs, hash_needed: true,
 | 
			
		||||
                                                   user_agent: user_agent)
 | 
			
		||||
          rescue Timeout::Error
 | 
			
		||||
            next
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
          next unless http_status_ok?(secure_details[:status])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user