exceptions.rb: Add DownloadError

`DownloadError` is an exception that download stratigies can throw to indicate
that a fetch was incomplete due to a failure in communication.

The `curl` method in `utils.rb` has been upgraded to throw a `DownloadError` if
something bad happens to `curl` execution.
This commit is contained in:
Charlie Sharpsteen 2011-09-14 12:18:35 -07:00
parent 560fb2dbcb
commit ff7c886556
2 changed files with 20 additions and 1 deletions

View File

@ -112,3 +112,17 @@ class BuildError < Homebrew::InstallationError
@command == './configure' @command == './configure'
end end
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
end

View File

@ -1,4 +1,5 @@
require 'pathname' require 'pathname'
require 'exceptions'
class Tty class Tty
class <<self class <<self
@ -104,10 +105,14 @@ def quiet_system cmd, *args
end end
def curl *args def curl *args
curl = Pathname.new '/usr/bin/curl'
raise "#{curl} is not an executable!" unless curl.exist? and curl.executable?
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
safe_system '/usr/bin/curl', HOMEBREW_CURL_ARGS, HOMEBREW_USER_AGENT, *args unless args.empty? raise DownloadError.new curl, args, $? unless Homebrew.system curl, *args
end end
def puts_columns items, star_items=[] def puts_columns items, star_items=[]