about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-19 00:10:15 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-19 00:10:15 +0000
commit01f65edf9594fdd811c5671a429b98ffff6f6523 (patch)
tree67c8a6d838657e18c4c460450000581b11871525
parentcbce24009023b7cbd751c8c027281673d0cdaa27 (diff)
downloadmogilefs-client-01f65edf9594fdd811c5671a429b98ffff6f6523.tar.gz
Overwriting data is bad, sometimes
-rwxr-xr-xbin/mog7
1 files changed, 7 insertions, 0 deletions
diff --git a/bin/mog b/bin/mog
index 5b38bb4..f46e0e7 100755
--- a/bin/mog
+++ b/bin/mog
@@ -53,6 +53,9 @@ ARGV.options do |x|
 
   x.on('-e', 'True if key exists') { test[:e] = true }
   x.on('-r', '--raw', 'show raw big_info file information') { cat[:raw] = true }
+  x.on('-n', '--no-clobber', 'do not clobber existing key') do
+    cli_cfg[:noclobber] = true
+  end
 
   x.on('-C', '--class=s', 'class') { |klass| cli_cfg[:class] = klass }
   x.on('-d', '--domain=s', 'domain') { |domain| cli_cfg[:domain] = domain }
@@ -137,6 +140,8 @@ begin
     filename = ARGV.shift or raise ArgumentError, '<filename> <key>'
     dkey = ARGV.shift or raise ArgumentError, '<filename> <key>'
     ARGV.shift and raise ArgumentError, '<filename> <key>'
+    cfg[:noclobber] && mg.exist?(dkey) and
+      abort "`#{dkey}' already exists and -n/--no-clobber was specified"
     store_file_retry(mg, dkey, cfg[:class], filename)
   when 'cat'
     ARGV.empty? and raise ArgumentError, '<key1> [<key2> ...]'
@@ -191,6 +196,8 @@ begin
     require 'tempfile'
     dkey = ARGV.shift or raise ArgumentError, '<key>'
     ARGV.shift and raise ArgumentError, '<key>'
+    cfg[:noclobber] && mg.exist?(dkey) and
+      abort "`#{dkey}' already exists and -n/--no-clobber was specified"
     skip_tee = File.stat('/dev/null') == $stdout.stat
 
     if chunk