about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-13 06:53:21 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-13 06:53:21 +0000
commit63b390fb6e6ea43f20c42865efa2b370f4fb0c55 (patch)
tree6ca2b6a6984c894e25bba2679b2ceaa58a4b246d
parentfab3a54359e7ddd67b96be010ce7fcdee31b23a6 (diff)
downloadmogilefs-client-63b390fb6e6ea43f20c42865efa2b370f4fb0c55.tar.gz
* use warn instead of STDERR.puts
* prefer $std* to STD*, they're less ambiguous
* $stderr doesn't need binmode, we don't hit it directly
-rwxr-xr-xbin/mog29
1 files changed, 15 insertions, 14 deletions
diff --git a/bin/mog b/bin/mog
index c9888ec..f8647b6 100755
--- a/bin/mog
+++ b/bin/mog
@@ -1,7 +1,8 @@
 #!/usr/bin/env ruby
 require 'mogilefs'
 require 'optparse'
-[ STDIN, STDOUT, STDERR].each { |io| io.binmode }
+$stdin.binmode
+$stdout.binmode
 $stderr.sync = $stdout.sync = true
 
 trap('INT') { exit 130 }
@@ -19,7 +20,7 @@ def parse_config_file!(path, overwrite = false)
     elsif m = /^timeout\s*=\s*(.*)/.match(line)
       dest[:timeout] = m[1].to_f
     else
-      STDERR.puts "Ignored configuration line: #{line}" unless /^#/.match(line)
+      warn "Ignored configuration line: #{line}" unless /^#/.match(line)
     end
   end
   dest
@@ -87,13 +88,13 @@ err = []
 err << "trackers must be specified" if cfg[:hosts].nil? || cfg[:hosts].empty?
 err << "domain must be specified" unless cfg[:domain]
 if err.any?
-  STDERR.puts "Errors:\n  #{err.join("\n  ")}"
-  STDERR.puts ARGV.options
+  warn "Errors:\n  #{err.join("\n  ")}"
+  warn ARGV.options
   exit 1
 end
 
 unless cmd = ARGV.shift
-  STDERR.puts ARGV.options
+  warn ARGV.options
   exit 1
 end
 
@@ -107,10 +108,10 @@ def store_file_retry(mg, key, storage_class, filepath)
   rescue MogileFS::UnreadableSocketError,
          MogileFS::Backend::NoDevicesError => err
     if ((tries += 1) < 10)
-      STDERR.puts "Retrying on error: #{err}: #{err.message} tries: #{tries}"
+      warn "Retrying on error: #{err}: #{err.message} tries: #{tries}"
       retry
     else
-      STDERR.puts "FATAL: #{err}: #{err.message} tries: #{tries}"
+      warn "FATAL: #{err}: #{err.message} tries: #{tries}"
     end
     exit 1
   end
@@ -139,9 +140,9 @@ begin
     ARGV.empty? and raise ArgumentError, '<key1> [<key2> ...]'
     ARGV.each do |key|
       if (!cat[:raw] && key =~ /^_big_info:/)
-        mg.bigfile_write(key, STDOUT, {:verify => true})
+        mg.bigfile_write(key, $stdout, {:verify => true})
       else
-        mg.get_file_data(key, STDOUT)
+        mg.get_file_data(key, $stdout)
       end
     end
   when 'ls'
@@ -175,7 +176,7 @@ begin
         end
         puts ""
       else
-        STDERR.puts "No such key: #{key}"
+        warn "No such key: #{key}"
       end
     end
   when 'tee'
@@ -188,10 +189,10 @@ begin
 
     # if stdout is pointing to /dev/null, don't bother installing the filter.
     tee_obj = tmp
-    if File.stat('/dev/null') != STDOUT.stat
+    if File.stat('/dev/null') != $stdout.stat
       tee_obj = lambda do |buf|
         rv = nil
-        [ STDOUT, tmp ].each { |io| rv = io.write(buf) }
+        [ $stdout, tmp ].each { |io| rv = io.write(buf) }
         rv
       end
       def tee_obj.write(buf)
@@ -199,7 +200,7 @@ begin
       end
     end
     begin
-      MogileFS::X.copy_stream(STDIN, tee_obj)
+      MogileFS::X.copy_stream($stdin, tee_obj)
       store_file_retry(mg, key, cfg[:class], tmp.path)
     ensure
       tmp.close!
@@ -233,7 +234,7 @@ begin
     raise ArgumentError, "Unknown command: #{cmd}"
   end
 rescue ArgumentError => err
-  STDERR.puts "Usage: #{$0} #{cmd} #{err.message}"
+  warn "Usage: #{$0} #{cmd} #{err.message}"
   exit 1
 end
 exit 0