From: David Zafman Date: Fri, 5 Dec 2014 02:53:08 +0000 (-0800) Subject: ceph_objectstore_tool: Accept json object with --pgid instead of array X-Git-Tag: v0.91~40^2~3^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=59b423e2e8846b098326fdec440de46b8e3d2769;p=ceph.git ceph_objectstore_tool: Accept json object with --pgid instead of array It isn't anticipated that anyone would use this but keeps backward compatible Signed-off-by: David Zafman --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index d4821b5ff0589..1d430e8f9f7a7 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -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::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::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());