diff options
| author | Jack Nagel | 2014-09-05 15:13:52 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-09-05 15:13:52 -0500 |
| commit | 96042e5481c8549dae82f156909cbb6eeaf666df (patch) | |
| tree | 9d8b952aaa80052dacaa0beb0027aae33b12c12a /Library/Homebrew/formula.rb | |
| parent | a7f8d8cdb5f0805817f830112243501537ed0dac (diff) | |
| download | homebrew-96042e5481c8549dae82f156909cbb6eeaf666df.tar.bz2 | |
Reduce effective scope of pipe variables
Diffstat (limited to 'Library/Homebrew/formula.rb')
| -rw-r--r-- | Library/Homebrew/formula.rb | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6965a452e..da7f081b9 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -493,8 +493,6 @@ class Formula # Pretty titles the command and buffers stdout/stderr # Throws if there's an error def system cmd, *args - rd, wr = IO.pipe - # remove "boring" arguments so that the important ones are more likely to # be shown considering that we trim long ohai lines to the terminal width pretty_args = args.dup @@ -510,39 +508,43 @@ class Formula logfn = "#{logd}/%02d.%s" % [@exec_count, File.basename(cmd).split(' ').first] mkdir_p(logd) - pid = fork { exec_cmd(cmd, args, rd, wr, logfn) } - wr.close - - File.open(logfn, 'w') do |f| - f.puts Time.now, "", cmd, args, "" + rd, wr = IO.pipe - if ARGV.verbose? - while buf = rd.gets - f.puts buf - puts buf + begin + pid = fork { exec_cmd(cmd, args, rd, wr, logfn) } + wr.close + + File.open(logfn, 'w') do |f| + f.puts Time.now, "", cmd, args, "" + + if ARGV.verbose? + while buf = rd.gets + f.puts buf + puts buf + end + elsif IO.respond_to?(:copy_stream) + IO.copy_stream(rd, f) + else + buf = "" + f.write(buf) while rd.read(1024, buf) end - elsif IO.respond_to?(:copy_stream) - IO.copy_stream(rd, f) - else - buf = "" - f.write(buf) while rd.read(1024, buf) - end - Process.wait(pid) + Process.wait(pid) - $stdout.flush + $stdout.flush - unless $?.success? - f.flush - Kernel.system "/usr/bin/tail", "-n", "5", logfn unless ARGV.verbose? - f.puts - require 'cmd/config' - Homebrew.dump_build_config(f) - raise BuildError.new(self, cmd, args) + unless $?.success? + f.flush + Kernel.system "/usr/bin/tail", "-n", "5", logfn unless ARGV.verbose? + f.puts + require 'cmd/config' + Homebrew.dump_build_config(f) + raise BuildError.new(self, cmd, args) + end end + ensure + rd.close unless rd.closed? end - ensure - rd.close unless rd.closed? end private |
