aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2009-11-06 17:09:14 +0000
committerMax Howell2009-11-08 15:21:09 +0000
commit22afc5e1c7c1d2141232f85eeb1436061ddfd835 (patch)
tree3bf69ba50b5c97919fae1d2a9cd6044846941dcc /Library
parent1e879eaee8815eebd3bc3f5318f62d1e86b4d62a (diff)
downloadbrew-22afc5e1c7c1d2141232f85eeb1436061ddfd835.tar.bz2
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.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb24
-rw-r--r--Library/Homebrew/formula_installer.rb7
-rw-r--r--Library/Homebrew/utils.rb7
3 files changed, 21 insertions, 17 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 0cf351ba2..9c88c8d71 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -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
+ out = ''
+ ignore_interrupts do
+ wr.close
+ out << rd.read until rd.eof?
end
- unless $? == 0
- puts "Exit code: #{$?}"
+ unless $?.success?
puts out
raise
end
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index 326d8ed51..498029d2f 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -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
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 0f94cce6e..e30512ff9 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -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