diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-15 16:30:15 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-15 16:30:37 -0700 |
commit | 2c09ff42b2e96f28dda283730bdb9deb68946843 (patch) | |
tree | 69029e602cae877155306bd23de9dc4740e2f8df /lib | |
parent | 0d4068e5e890aad959419ad932a162ab170868c5 (diff) | |
download | mogilefs-client-2c09ff42b2e96f28dda283730bdb9deb68946843.tar.gz |
Also easier to trap and deal with
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mogilefs.rb | 5 | ||||
-rw-r--r-- | lib/mogilefs/admin.rb | 10 | ||||
-rw-r--r-- | lib/mogilefs/mogilefs.rb | 10 |
3 files changed, 15 insertions, 10 deletions
diff --git a/lib/mogilefs.rb b/lib/mogilefs.rb index 8f499e5..0d37d34 100644 --- a/lib/mogilefs.rb +++ b/lib/mogilefs.rb @@ -13,6 +13,11 @@ module MogileFS class Error < StandardError; end class UnreadableSocketError < Error; end + class ReadOnlyError < Error + def message + 'readonly mogilefs' + end + end end diff --git a/lib/mogilefs/admin.rb b/lib/mogilefs/admin.rb index c03b394..d3774b7 100644 --- a/lib/mogilefs/admin.rb +++ b/lib/mogilefs/admin.rb @@ -155,7 +155,7 @@ class MogileFS::Admin < MogileFS::Client # Creates a new domain named +domain+. Returns nil if creation failed. def create_domain(domain) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? res = @backend.create_domain :domain => domain return res['domain'] unless res.nil? end @@ -164,7 +164,7 @@ class MogileFS::Admin < MogileFS::Client # Deletes +domain+. Returns true if successful, false if not. def delete_domain(domain) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? res = @backend.delete_domain :domain => domain return !res.nil? end @@ -216,7 +216,7 @@ class MogileFS::Admin < MogileFS::Client # Deletes host +host+. Returns nil on failure. def delete_host(host) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? res = @backend.delete_host :host => host return !res.nil? end @@ -226,7 +226,7 @@ class MogileFS::Admin < MogileFS::Client # 'alive', 'down', or 'dead'. def change_device_state(host, device, state) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? res = @backend.set_state :host => host, :device => device, :state => state return !res.nil? end @@ -238,7 +238,7 @@ class MogileFS::Admin < MogileFS::Client # +action+. Returns the class name if successful, nil if not. def modify_class(domain, klass, mindevcount, action) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? res = @backend.send("#{action}_class", :domain => domain, :class => klass, :mindevcount => mindevcount) diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb index 848061e..0a62dba 100644 --- a/lib/mogilefs/mogilefs.rb +++ b/lib/mogilefs/mogilefs.rb @@ -121,7 +121,7 @@ class MogileFS::MogileFS < MogileFS::Client # The +block+ operates like File.open. def new_file(key, klass, bytes = 0, &block) # :yields: file - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? res = @backend.create_open(:domain => @domain, :class => klass, :key => key, :multi_dest => 1) @@ -161,7 +161,7 @@ class MogileFS::MogileFS < MogileFS::Client # either a file name or an object that responds to #read. def store_file(key, klass, file) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? new_file key, klass do |mfp| if file.respond_to? :sysread then @@ -181,7 +181,7 @@ class MogileFS::MogileFS < MogileFS::Client # Stores +content+ into +key+ in class +klass+. def store_content(key, klass, content) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? new_file key, klass do |mfp| mfp << content @@ -194,7 +194,7 @@ class MogileFS::MogileFS < MogileFS::Client # Removes +key+. def delete(key) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? @backend.delete :domain => @domain, :key => key end @@ -210,7 +210,7 @@ class MogileFS::MogileFS < MogileFS::Client # Renames a key +from+ to key +to+. def rename(from, to) - raise 'readonly mogilefs' if readonly? + raise MogileFS::ReadOnlyError if readonly? @backend.rename :domain => @domain, :from_key => from, :to_key => to nil |