diff options
| author | Markus Reiter | 2017-08-08 19:26:33 +0200 |
|---|---|---|
| committer | GitHub | 2017-08-08 19:26:33 +0200 |
| commit | 1a30c165bfb82ae846e64c508f06455e0d3f285e (patch) | |
| tree | ab63c314bed39e41dfe47273902ca14c15515c23 /Library/Homebrew/utils | |
| parent | 93051b27d6886dae6df01544c86df579f21f6410 (diff) | |
| parent | ae4bafdb365cfa380d129b0a03bd99a1e4d960a4 (diff) | |
| download | brew-1a30c165bfb82ae846e64c508f06455e0d3f285e.tar.bz2 | |
Merge pull request #3026 from reitermarkus/refactor-download-strategies
Refactor download strategies.
Diffstat (limited to 'Library/Homebrew/utils')
| -rw-r--r-- | Library/Homebrew/utils/curl.rb | 42 | ||||
| -rw-r--r-- | Library/Homebrew/utils/github.rb | 2 |
2 files changed, 24 insertions, 20 deletions
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 5a40ae846..6aaf9be0c 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,42 +1,46 @@ require "pathname" require "open3" -def curl_args(options = {}) +def curl_executable curl = Pathname.new ENV["HOMEBREW_CURL"] curl = Pathname.new "/usr/bin/curl" unless curl.exist? - raise "#{curl} is not executable" unless curl.exist? && curl.executable? + return curl if curl.executable? + raise "#{curl} is not executable" +end +def curl_args(*extra_args, show_output: false, user_agent: :default) args = [ - curl.to_s, - "--remote-time", - "--location", + curl_executable.to_s, + "--fail", + "--show-error", ] - case options[:user_agent] - when :browser - args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI + args << "--user-agent" << case user_agent + when :browser, :fake + HOMEBREW_USER_AGENT_FAKE_SAFARI + when :default + HOMEBREW_USER_AGENT_CURL else - args << "--user-agent" << HOMEBREW_USER_AGENT_CURL + user_agent end - unless options[:show_output] + unless show_output args << "--progress-bar" unless ARGV.verbose? args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] - args << "--fail" args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] end - args += options[:extra_args] if options[:extra_args] - args + args + extra_args end def curl(*args) - safe_system(*curl_args(extra_args: args)) + safe_system(*curl_args(*args)) end -def curl_output(*args) - curl_args = curl_args(extra_args: args, show_output: true) - Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread| - [stdout.read, stderr.read, wait_thread.value] - end +def curl_download(*args, to: nil, **options) + curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options) +end + +def curl_output(*args, **options) + Open3.capture3(*curl_args(*args, show_output: true, **options)) end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 1a781cee6..07eea4384 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, *args) + output, errors, status = curl_output(url.to_s, "--location", *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read |
