From 0eaf4bbcd9e4afb8a92a678ee072e8167e841527 Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Tue, 11 Aug 2009 12:20:55 -0700 Subject: 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 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. --- Library/Homebrew/utils.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Library/Homebrew/utils.rb') 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 -- cgit v1.2.3