Handle exceptions during install correctly

rm -rf the prefix and build dirs when appropriate.
This commit is contained in:
Max Howell 2009-06-08 11:43:28 +01:00
parent cbbc7b0f0f
commit 71a6287409
2 changed files with 32 additions and 26 deletions

View File

@ -178,32 +178,30 @@ public
# yields self with current working directory set to the uncompressed tarball # yields self with current working directory set to the uncompressed tarball
def brew def brew
ohai "Downloading #{@url}" ohai "Downloading #{@url}"
Dir.chdir appsupport do Dir.chdir appsupport do
tgz=Pathname.new(fetch()).realpath tmp=tgz=nil
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
begin 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 tmp=`mktemp -dt #{File.basename @url}`.strip
Dir.chdir tmp do Dir.chdir tmp do
Dir.chdir uncompress(tgz) do Dir.chdir uncompress(tgz) do
yield self yield self
end end
end end
rescue => e rescue Interrupt, RuntimeError
if e.kind_of? Interrupt and ARGV.include? '--debug' if ARGV.include? '--debug'
# debug mode allows the packager to intercept a failed build and # debug mode allows the packager to intercept a failed build and
# investigate the problems # investigate the problems
puts "Rescued build at: #{tmp}" puts "Rescued build at: #{tmp}"
exit! 1 exit! 1
else else
FileUtils.rm_rf prefix
raise raise
end end
ensure ensure

View File

@ -212,20 +212,28 @@ begin
shift_formulae_from_ARGV.each do |name| shift_formulae_from_ARGV.each do |name|
beginning = Time.now beginning = Time.now
o=__obj(name) o=__obj(name)
raise "#{o.prefix} already exists!" if o.prefix.exist? begin
o.prefix.mkpath raise "#{o.prefix} already exists!" if o.prefix.exist?
o.brew { o.install } o.prefix.mkpath
ohai 'Finishing up' o.brew do
#TODO copy changelog or CHANGES file to pkg root, o.install
#TODO maybe README, etc. to versioned root ['README','ChangeLog','COPYING','AUTHORS'].each do |file|
o.clean FileUtils.cp file, o.prefix if File.file? file
ln name end
if o.caveats end
ohai "Caveats" ohai 'Finishing up'
puts o.caveats o.clean
ohai "Summary" 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 end
puts "#{o.prefix}: "+abv(name)+", built in #{Time.now - beginning} seconds"
end end
when 'ln' when 'ln'
n=0 n=0