Only try mirrors for CurlDownloadStrategies
Also adjust output text slightly for prettiness. A possibly useful side effect here is safe_system has a defined Exception (subclassing RuntimeError) now.
This commit is contained in:
parent
1dc0775a15
commit
6bd47cf0f9
@ -55,10 +55,14 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
|
|||||||
unless @tarball_path.exist?
|
unless @tarball_path.exist?
|
||||||
begin
|
begin
|
||||||
_fetch
|
_fetch
|
||||||
rescue Exception
|
rescue Exception => e
|
||||||
ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? }
|
ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? }
|
||||||
|
if e.kind_of? ErrorDuringExecution
|
||||||
|
raise CurlDownloadStrategyError, "Download failed: #{@url}"
|
||||||
|
else
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts "File already downloaded in #{File.dirname(@tarball_path)}"
|
puts "File already downloaded in #{File.dirname(@tarball_path)}"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -113,16 +113,10 @@ class BuildError < Homebrew::InstallationError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class DownloadError < RuntimeError
|
# raised in CurlDownloadStrategy.fetch
|
||||||
attr :command
|
class CurlDownloadStrategyError < RuntimeError
|
||||||
attr :args
|
end
|
||||||
attr :exit_status
|
|
||||||
|
# raised by safe_system in utils.rb
|
||||||
def initialize cmd, args, status
|
class ErrorDuringExecution < RuntimeError
|
||||||
@command = cmd
|
|
||||||
@args = args
|
|
||||||
args.map!{ |arg| arg.to_s.gsub " ", "\\ " }
|
|
||||||
super "#{cmd} #{args.join ' '}\nDownloader failed with exit status #{status}"
|
|
||||||
@exit_status = status
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -561,9 +561,9 @@ private
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
fetched = downloader.fetch
|
fetched = downloader.fetch
|
||||||
rescue DownloadError => e
|
rescue CurlDownloadStrategyError => e
|
||||||
raise e if mirror_list.empty?
|
raise e if mirror_list.empty?
|
||||||
opoo "#{e.message}\nTrying a mirror."
|
puts "Trying a mirror..."
|
||||||
url, specs = mirror_list.shift.values_at :url, :specs
|
url, specs = mirror_list.shift.values_at :url, :specs
|
||||||
downloader = download_strategy.new url, name, version, specs
|
downloader = download_strategy.new url, name, version, specs
|
||||||
retry
|
retry
|
||||||
|
|||||||
@ -92,7 +92,7 @@ end
|
|||||||
def safe_system cmd, *args
|
def safe_system cmd, *args
|
||||||
unless Homebrew.system cmd, *args
|
unless Homebrew.system cmd, *args
|
||||||
args = args.map{ |arg| arg.to_s.gsub " ", "\\ " } * " "
|
args = args.map{ |arg| arg.to_s.gsub " ", "\\ " } * " "
|
||||||
raise "Failure while executing: #{cmd} #{args}"
|
raise ErrorDuringExecution, "Failure while executing: #{cmd} #{args}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -106,13 +106,13 @@ end
|
|||||||
|
|
||||||
def curl *args
|
def curl *args
|
||||||
curl = Pathname.new '/usr/bin/curl'
|
curl = Pathname.new '/usr/bin/curl'
|
||||||
raise "#{curl} is not an executable!" unless curl.exist? and curl.executable?
|
raise "#{curl} is not executable" unless curl.exist? and curl.executable?
|
||||||
|
|
||||||
args = [HOMEBREW_CURL_ARGS, HOMEBREW_USER_AGENT, *args]
|
args = [HOMEBREW_CURL_ARGS, HOMEBREW_USER_AGENT, *args]
|
||||||
# See https://github.com/mxcl/homebrew/issues/6103
|
# See https://github.com/mxcl/homebrew/issues/6103
|
||||||
args << "--insecure" if MacOS.version < 10.6
|
args << "--insecure" if MacOS.version < 10.6
|
||||||
|
|
||||||
raise DownloadError.new curl, args, $? unless Homebrew.system curl, *args
|
safe_system curl, *args
|
||||||
end
|
end
|
||||||
|
|
||||||
def puts_columns items, star_items=[]
|
def puts_columns items, star_items=[]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user