]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: ceph-kvstore-tool: output value contents to file on 'get'
authorJoao Eduardo Luis <joao.luis@inktank.com>
Thu, 5 Dec 2013 12:08:35 +0000 (12:08 +0000)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Fri, 6 Dec 2013 01:06:17 +0000 (01:06 +0000)
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/tools/ceph-kvstore-tool.cc

index e07391d5c5107642b2e894e5da39890564ad14d6..76f68294cbed5e75d22614f031344b69505736f8 100644 (file)
@@ -214,7 +214,7 @@ void usage(const char *pname)
     << "  list [prefix]\n"
     << "  list-crc [prefix]\n"
     << "  exists <prefix> [key]\n"
-    << "  get <prefix> <key>\n"
+    << "  get <prefix> <key> [out <file>]\n"
     << "  crc <prefix> <key>\n"
     << "  get-size\n"
     << "  set <prefix> <key> [ver <N>|in <file>]\n"
@@ -286,9 +286,33 @@ int main(int argc, const char *argv[])
       return 1;
     }
     std::cout << std::endl;
-    ostringstream os;
-    bl.hexdump(os);
-    std::cout << os.str() << std::endl;
+
+    if (argc >= 6) {
+      string subcmd(argv[5]);
+      string out(argv[6]);
+
+      if (subcmd != "out") {
+        std::cerr << "unrecognized subcmd '" << subcmd << "'"
+                  << std::endl;
+        return 1;
+      }
+
+      if (out.empty()) {
+        std::cerr << "unspecified out file" << std::endl;
+        return 1;
+      }
+
+      int err = bl.write_file(argv[6], 0644);
+      if (err < 0) {
+        std::cerr << "error writing value to '" << out << "': "
+                  << cpp_strerror(err) << std::endl;
+        return 1;
+      }
+    } else {
+      ostringstream os;
+      bl.hexdump(os);
+      std::cout << os.str() << std::endl;
+    }
 
   } else if (cmd == "crc") {
     if (argc < 5) {