]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_objectstore_tool: Accept json object with --pgid instead of array 3020/head
authorDavid Zafman <dzafman@redhat.com>
Fri, 5 Dec 2014 02:53:08 +0000 (18:53 -0800)
committerLoic Dachary <ldachary@redhat.com>
Fri, 5 Dec 2014 20:09:42 +0000 (21:09 +0100)
It isn't anticipated that anyone would use this but keeps backward compatible

Signed-off-by: David Zafman <dzafman@redhat.com>
src/tools/ceph_objectstore_tool.cc

index d4821b5ff0589bd04c4d36c748c35820a22d0b9f..1d430e8f9f7a79f09a0f2efecc03cfb6b7faa58b 100644 (file)
@@ -2342,37 +2342,40 @@ int main(int argc, char **argv)
        }
       } else {
        stringstream ss;
-       if (v.type() != json_spirit::array_type) {
+       if (pgidstr.length() == 0 && v.type() != json_spirit::array_type) {
          ss << "object '" << object
             << "' must be a JSON array but is of type "
             << v.type() << " instead";
          throw std::runtime_error(ss.str());
        }
-       json_spirit::Array array = v.get_array();
-       vector<json_spirit::Value>::iterator i = array.begin();
-        if (i->type() != json_spirit::str_type) {
-         ss << "object '" << object
-            << "' must be a JSON array with the first element a string but "
-            << "found type " << v.type() << " instead";
-         throw std::runtime_error(ss.str());
-        }
-       string object_pgidstr = i->get_str();
-       spg_t object_pgid;
-       object_pgid.parse(object_pgidstr.c_str());
-       if (pgidstr.length() > 0) {
-         if (object_pgid != pgid) {
+       if (v.type() == json_spirit::array_type) {
+         json_spirit::Array array = v.get_array();
+         vector<json_spirit::Value>::iterator i = array.begin();
+         if (i->type() != json_spirit::str_type) {
            ss << "object '" << object
-              << "' has a pgid different from the --pgid="
-              << pgidstr << " option";
+              << "' must be a JSON array with the first element a string but "
+              << "found type " << v.type() << " instead";
            throw std::runtime_error(ss.str());
          }
-       } else {
-         pgidstr = object_pgidstr;
-         pgid = object_pgid;
+         string object_pgidstr = i->get_str();
+         spg_t object_pgid;
+         object_pgid.parse(object_pgidstr.c_str());
+         if (pgidstr.length() > 0) {
+           if (object_pgid != pgid) {
+             ss << "object '" << object
+                << "' has a pgid different from the --pgid="
+                << pgidstr << " option";
+             throw std::runtime_error(ss.str());
+           }
+         } else {
+           pgidstr = object_pgidstr;
+           pgid = object_pgid;
+         }
+         i++;
+         v = *i;
        }
-       i++;
        try {
-         ghobj.decode(*i);
+         ghobj.decode(v);
        } catch (std::runtime_error& e) {
          ss << "Decode object json error: " << e.what();
          throw std::runtime_error(ss.str());