Use our own popen implementation in Formula.system

The rationale here is that the --verbose mode had a bug where it didn't escape its parameters properly. Which caused ocassionally cryptic issues.
This commit is contained in:
Max Howell 2009-11-06 17:09:14 +00:00
parent 1e879eaee8
commit 22afc5e1c7
3 changed files with 21 additions and 17 deletions

View File

@ -216,20 +216,24 @@ protected
# Pretty titles the command and buffers stdout/stderr
# Throws if there's an error
def system cmd, *args
full="#{cmd} #{args*' '}".strip
ohai full
ohai "#{cmd} #{args*' '}".strip
if ARGV.verbose?
safe_system cmd, *args
else
out=''
# TODO write a ruby extension that does a good popen :P
IO.popen "#{full} 2>&1" do |f|
until f.eof?
out+=f.gets
end
rd, wr = IO.pipe
fork do
rd.close
$stdout.reopen wr
$stderr.reopen wr
exec cmd, *args
end
unless $? == 0
puts "Exit code: #{$?}"
out = ''
ignore_interrupts do
wr.close
out << rd.read until rd.eof?
end
unless $?.success?
puts out
raise
end

View File

@ -2,13 +2,6 @@ require 'beer_events'
require 'formula'
require 'set'
def ignore_interrupts
std_trap = trap("INT") {}
yield
ensure
trap("INT", std_trap)
end
class FormulaInstaller
@@attempted = Set.new

View File

@ -150,3 +150,10 @@ def inreplace path, before, after
f.reopen(path, 'w').write(o)
f.close
end
def ignore_interrupts
std_trap = trap("INT") {}
yield
ensure
trap("INT", std_trap)
end