From 771a28427cc241f957a030502b386d0fd9bfa5b7 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 7 Sep 2013 10:22:58 -0500 Subject: [PATCH] Use block-form of File.open and let Ruby do the cleanup --- Library/Homebrew/formula.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f01ca768af..15561b1001 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -572,24 +572,25 @@ class Formula end wr.close - f = File.open(logfn, 'w') - f.write(rd.read) until rd.eof? + File.open(logfn, 'w') do |f| + f.write(rd.read) until rd.eof? - Process.wait + Process.wait - unless $?.success? - f.flush - Kernel.system "/usr/bin/tail", "-n", "5", logfn - f.puts - require 'cmd/--config' - Homebrew.write_build_config(f) - raise ErrorDuringExecution + unless $?.success? + f.flush + Kernel.system "/usr/bin/tail", "-n", "5", logfn + f.puts + require 'cmd/--config' + Homebrew.write_build_config(f) + raise ErrorDuringExecution + end end end rescue ErrorDuringExecution raise BuildError.new(self, cmd, args, $?) ensure - [rd, f].each { |io| io.close if io and not io.closed? } + rd.close if rd and not rd.closed? ENV.update(removed_ENV_variables) if removed_ENV_variables end