From 6bd47cf0f96447e5ee0925eea34e406bdaed7ffa Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 19 Sep 2011 23:29:07 +0100 Subject: [PATCH] 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. --- Library/Homebrew/download_strategy.rb | 8 ++++++-- Library/Homebrew/exceptions.rb | 18 ++++++------------ Library/Homebrew/formula.rb | 4 ++-- Library/Homebrew/utils.rb | 6 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index d043ef450e..f63ed98a32 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -55,9 +55,13 @@ class CurlDownloadStrategy < AbstractDownloadStrategy unless @tarball_path.exist? begin _fetch - rescue Exception + rescue Exception => e ignore_interrupts { @tarball_path.unlink if @tarball_path.exist? } - raise + if e.kind_of? ErrorDuringExecution + raise CurlDownloadStrategyError, "Download failed: #{@url}" + else + raise + end end else puts "File already downloaded in #{File.dirname(@tarball_path)}" diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index e77c0573a3..cd5103963f 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -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 diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6ed03af14c..f8d86844f5 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -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 diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 4859956154..dc7bf5d42a 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -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=[]