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:
Max Howell 2011-09-19 23:29:07 +01:00
parent 1dc0775a15
commit 6bd47cf0f9
4 changed files with 17 additions and 19 deletions

View File

@ -55,10 +55,14 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
unless @tarball_path.exist?
begin
_fetch
rescue Exception
rescue Exception => e
ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? }
if e.kind_of? ErrorDuringExecution
raise CurlDownloadStrategyError, "Download failed: #{@url}"
else
raise
end
end
else
puts "File already downloaded in #{File.dirname(@tarball_path)}"
end

View File

@ -113,16 +113,10 @@ class BuildError < Homebrew::InstallationError
end
end
class DownloadError < RuntimeError
attr :command
attr :args
attr :exit_status
def initialize cmd, args, status
@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
# raised in CurlDownloadStrategy.fetch
class CurlDownloadStrategyError < RuntimeError
end
# raised by safe_system in utils.rb
class ErrorDuringExecution < RuntimeError
end

View File

@ -561,9 +561,9 @@ private
begin
fetched = downloader.fetch
rescue DownloadError => e
rescue CurlDownloadStrategyError => e
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
downloader = download_strategy.new url, name, version, specs
retry

View File

@ -92,7 +92,7 @@ end
def safe_system cmd, *args
unless Homebrew.system cmd, *args
args = args.map{ |arg| arg.to_s.gsub " ", "\\ " } * " "
raise "Failure while executing: #{cmd} #{args}"
raise ErrorDuringExecution, "Failure while executing: #{cmd} #{args}"
end
end
@ -106,13 +106,13 @@ end
def curl *args
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]
# See https://github.com/mxcl/homebrew/issues/6103
args << "--insecure" if MacOS.version < 10.6
raise DownloadError.new curl, args, $? unless Homebrew.system curl, *args
safe_system curl, *args
end
def puts_columns items, star_items=[]