diff options
| author | Adam Vandenberg | 2009-08-11 12:20:55 -0700 |
|---|---|---|
| committer | Max Howell | 2009-08-24 01:03:23 +0100 |
| commit | 0eaf4bbcd9e4afb8a92a678ee072e8167e841527 (patch) | |
| tree | 914109b77c2bfe864165521c2af84e26953dc27c /Library/Homebrew/utils.rb | |
| parent | 65e1419ea977c6ea1f4edd6ebf24f48c84fa0832 (diff) | |
| download | brew-0eaf4bbcd9e4afb8a92a678ee072e8167e841527.tar.bz2 | |
Factor out downloading from Formula
This patch adds a ArchiveDownloadStrategy that handles downloading
tarbarlls and decompressing them into the staging area ready for brewing.
Refactored safe_system and curl into utils.rb
Signed-off-by: Max Howell <max@methylblue.com>
Modifications to Adam's original patch:
I reverted objectification of checksum verification because I couldn't think
of any other download validation methods that might be useful to us in the
future, so allowing such flexibility had no advantages. If we ever need this
to be OO we can add it. But for now less complexity is preferable.
I removed the @svnurl class member. Instead download_strategy is autodetected
by examining the url. The user can override the download_strategy in case this
fails. Thus we already can easily add support for clones of git repositories.
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 7c86faf1b..06b9cab21 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -49,3 +49,17 @@ def interactive_shell Process.wait pid end end + +# Kernel.system but with exceptions +def safe_system cmd, *args + puts "#{cmd} #{args*' '}" if ARGV.verbose? + + execd=Kernel.system cmd, *args + # somehow Ruby doesn't handle the CTRL-C from another process -- WTF!? + raise Interrupt, cmd if $?.termsig == 2 + raise ExecutionError.new(cmd, args) unless execd and $? == 0 +end + +def curl url, *args + safe_system 'curl', '-f#LA', HOMEBREW_USER_AGENT, url, *args +end |
