From e6fb3c3114ea842884a49c7f2ddfe1a9c4e3eee0 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 25 Dec 2016 23:01:40 +0000 Subject: curl: make curl_args more configurable. Allow configuring whether output should be shown or the default the default user agent is used. --- Library/Homebrew/utils/curl.rb | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'Library/Homebrew/utils') diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 00c3a591c..eab623c40 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,27 +1,38 @@ require "pathname" require "open3" -def curl_args(extra_args = []) +def curl_args(options = {}) 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? - flags = HOMEBREW_CURL_ARGS - flags -= ["--progress-bar"] if ARGV.verbose? + args = [ + curl.to_s, + "--remote-time", + "--location", + ] - args = [curl.to_s] + flags + extra_args - args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] - args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] + unless options[:default_user_agent] + args << "--user-agent" << HOMEBREW_USER_AGENT_CURL + end + + unless options[: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 end def curl(*args) - safe_system(*curl_args(args)) + safe_system(*curl_args(extra_args: args)) end def curl_output(*args) - curl_args = curl_args(args) - curl_args -= ["--fail", "--silent"] + 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 -- cgit v1.2.3 From a3bffe70bcf33e6051140b1a93c9f48714605af6 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 4 Jan 2017 11:13:41 +0000 Subject: Use docs.brew.sh links. --- Library/Homebrew/utils/analytics.rb | 2 +- Library/Homebrew/utils/analytics.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Library/Homebrew/utils') diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index cc7ad54d2..7dd54d3f1 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -35,7 +35,7 @@ module Utils end # Send analytics. Don't send or store any personally identifiable information. - # https://github.com/Homebrew/brew/blob/master/docs/Analytics.md + # http://docs.brew.sh/Analytics.html # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters if ENV["HOMEBREW_ANALYTICS_DEBUG"] diff --git a/Library/Homebrew/utils/analytics.sh b/Library/Homebrew/utils/analytics.sh index 0f188fe9b..35f91eabc 100644 --- a/Library/Homebrew/utils/analytics.sh +++ b/Library/Homebrew/utils/analytics.sh @@ -107,7 +107,7 @@ report-analytics-screenview-command() { ) # Send analytics. Don't send or store any personally identifiable information. - # https://github.com/Homebrew/brew/blob/master/docs/Analytics.md + # http://docs.brew.sh/Analytics.html # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#screenView # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters if [[ -z "$HOMEBREW_ANALYTICS_DEBUG" ]] -- cgit v1.2.3 From e7a81caaf4bc0468fdc302656efebd584e10a3f6 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 7 Jan 2017 14:03:08 +0000 Subject: Allow `brew audit` to fake a Safari user-agent. This allows us to detect if homepages such as e.g. `aiccu` which blocks `curl` are up or not. --- Library/Homebrew/utils/curl.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/utils') diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index eab623c40..5a40ae846 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -12,7 +12,10 @@ def curl_args(options = {}) "--location", ] - unless options[:default_user_agent] + case options[:user_agent] + when :browser + args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI + else args << "--user-agent" << HOMEBREW_USER_AGENT_CURL end -- cgit v1.2.3 From ac7a59373087e9d49097ab7f0ddb691e64159959 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Thu, 12 Jan 2017 07:22:34 -0800 Subject: InreplaceError: fix undefined method crash When the first parameter to inreplace was an array, and the replacement failed, InreplaceError would end up crashing with an undefined method exception because the order of operations resulted in super not being passed the value of the entire inject block. --- Library/Homebrew/utils/inreplace.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/utils') diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index c7557ab41..b4c219f06 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -1,9 +1,10 @@ module Utils class InreplaceError < RuntimeError def initialize(errors) - super errors.inject("inreplace failed\n") do |s, (path, errs)| + formatted_errors = errors.inject("inreplace failed\n") do |s, (path, errs)| s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join end + super formatted_errors end end -- cgit v1.2.3