aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Howell2009-06-08 11:43:28 +0100
committerMax Howell2009-06-08 11:43:28 +0100
commit71a628740987ed5737440ec2f2f350e73c51452b (patch)
tree670fa52697960ef47fac2946a12eb3ce3793b977
parentcbbc7b0f0f00132c1c9a1beeadd230e4ad6e63e1 (diff)
downloadbrew-71a628740987ed5737440ec2f2f350e73c51452b.tar.bz2
Handle exceptions during install correctly
rm -rf the prefix and build dirs when appropriate.
-rw-r--r--Library/Homebrew/brewkit.rb24
-rwxr-xr-xbin/brew34
2 files changed, 32 insertions, 26 deletions
diff --git a/Library/Homebrew/brewkit.rb b/Library/Homebrew/brewkit.rb
index a51c080f5..a0c4d9a12 100644
--- a/Library/Homebrew/brewkit.rb
+++ b/Library/Homebrew/brewkit.rb
@@ -178,32 +178,30 @@ public
# yields self with current working directory set to the uncompressed tarball
def brew
ohai "Downloading #{@url}"
-
Dir.chdir appsupport do
- tgz=Pathname.new(fetch()).realpath
- md5=`md5 -q "#{tgz}"`.strip
- raise "MD5 mismatch: #{md5}" unless @md5 and md5 == @md5.downcase
-
- # we make an additional subdirectory so know exactly what we are
- # recursively deleting later
- # we use mktemp rather than appsupport/blah because some build scripts
- # can't handle being built in a directory with spaces in it :P
- tmp=nil
+ tmp=tgz=nil
begin
+ tgz=Pathname.new(fetch()).realpath
+ md5=`md5 -q "#{tgz}"`.strip
+ raise "MD5 mismatch: #{md5}" unless @md5 and md5 == @md5.downcase
+
+ # we make an additional subdirectory so know exactly what we are
+ # recursively deleting later
+ # we use mktemp rather than appsupport/blah because some build scripts
+ # can't handle being built in a directory with spaces in it :P
tmp=`mktemp -dt #{File.basename @url}`.strip
Dir.chdir tmp do
Dir.chdir uncompress(tgz) do
yield self
end
end
- rescue => e
- if e.kind_of? Interrupt and ARGV.include? '--debug'
+ rescue Interrupt, RuntimeError
+ if ARGV.include? '--debug'
# debug mode allows the packager to intercept a failed build and
# investigate the problems
puts "Rescued build at: #{tmp}"
exit! 1
else
- FileUtils.rm_rf prefix
raise
end
ensure
diff --git a/bin/brew b/bin/brew
index 73d8faf2f..f6ef1c392 100755
--- a/bin/brew
+++ b/bin/brew
@@ -212,20 +212,28 @@ begin
shift_formulae_from_ARGV.each do |name|
beginning = Time.now
o=__obj(name)
- raise "#{o.prefix} already exists!" if o.prefix.exist?
- o.prefix.mkpath
- o.brew { o.install }
- ohai 'Finishing up'
- #TODO copy changelog or CHANGES file to pkg root,
- #TODO maybe README, etc. to versioned root
- o.clean
- ln name
- if o.caveats
- ohai "Caveats"
- puts o.caveats
- ohai "Summary"
+ begin
+ raise "#{o.prefix} already exists!" if o.prefix.exist?
+ o.prefix.mkpath
+ o.brew do
+ o.install
+ ['README','ChangeLog','COPYING','AUTHORS'].each do |file|
+ FileUtils.cp file, o.prefix if File.file? file
+ end
+ end
+ ohai 'Finishing up'
+ o.clean
+ ln name
+ if o.caveats
+ ohai "Caveats"
+ puts o.caveats
+ ohai "Summary"
+ end
+ puts "#{o.prefix}: "+abv(name)+", built in #{Time.now - beginning} seconds"
+ rescue Exception
+ FileUtils.rm_rf o.prefix
+ raise
end
- puts "#{o.prefix}: "+abv(name)+", built in #{Time.now - beginning} seconds"
end
when 'ln'
n=0