diff options
Diffstat (limited to 'lib/rubygems/util.rb')
-rw-r--r-- | lib/rubygems/util.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb index 42663974a5..408942d398 100644 --- a/lib/rubygems/util.rb +++ b/lib/rubygems/util.rb @@ -1,4 +1,10 @@ +## +# This module contains various utility methods as module methods. + module Gem::Util + + @silent_mutex = nil + ## # Zlib::GzipReader wrapper that unzips +data+. @@ -60,4 +66,56 @@ module Gem::Util end end + ## + # Invokes system, but silences all output. + + def self.silent_system *command + require 'thread' + + @silent_mutex ||= Mutex.new + + null_device = Gem.win_platform? ? 'NUL' : '/dev/null' + + @silent_mutex.synchronize do + begin + stdout = STDOUT.dup + stderr = STDERR.dup + + STDOUT.reopen null_device, 'w' + STDERR.reopen null_device, 'w' + + return system(*command) + ensure + STDOUT.reopen stdout + STDERR.reopen stderr + end + end + end + + ## + # Enumerates the parents of +directory+. + + def self.traverse_parents directory + return enum_for __method__, directory unless block_given? + + here = File.expand_path directory + start = here + + Dir.chdir start + + begin + loop do + yield here + + Dir.chdir '..' + + return if Dir.pwd == here # toplevel + + here = Dir.pwd + end + ensure + Dir.chdir start + end + end + end |