about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-25 05:46:08 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-25 05:48:18 +0000
commitd806fa67899e697a2d399eff0553e9c3b60e484e (patch)
treedf7115d7851d262472387aac985e869c5b855178
parent0fce97034959a605e66ebd645bf4a1957bfed870 (diff)
downloadmogilefs-client-d806fa67899e697a2d399eff0553e9c3b60e484e.tar.gz
Easier for me to read, this way, and OK lines are usually more
common than ERR lines :P
-rw-r--r--lib/mogilefs/backend.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/mogilefs/backend.rb b/lib/mogilefs/backend.rb
index 454685a..7818f6e 100644
--- a/lib/mogilefs/backend.rb
+++ b/lib/mogilefs/backend.rb
@@ -295,7 +295,10 @@ class MogileFS::Backend
   # Turns the +line+ response from the server into a Hash of options, an
   # error, or raises, as appropriate.
   def parse_response(line, request = nil)
-    if line =~ /^ERR\s+(\w+)\s*([^\r\n]*)/
+    case line
+    when /\AOK\s+\d*\s*(\S*)\r?\n\z/
+      url_decode($1)
+    when /\AERR\s+(\w+)\s*([^\r\n]*)/
       @lasterr = $1
       @lasterrstr = $2 ? url_unescape($2) : nil
       if request
@@ -304,12 +307,10 @@ class MogileFS::Backend
         return error(@lasterr).new(@lasterrstr)
       end
       raise error(@lasterr).new(@lasterrstr)
+    else
+      raise MogileFS::InvalidResponseError,
+            "Invalid response from server: #{line.inspect}"
     end
-
-    return url_decode($1) if line =~ /^OK\s+\d*\s*(\S*)\r\n\z/
-
-    raise MogileFS::InvalidResponseError,
-          "Invalid response from server: #{line.inspect}"
   end
 
   # this command is special since the cache is per-tracker, so we connect