]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rados: add touch command to change object modification time 18913/head
authorYao Zongyou <yaozongyou@vip.qq.com>
Tue, 14 Nov 2017 09:34:03 +0000 (17:34 +0800)
committerYao Zongyou <yaozongyou@vip.qq.com>
Tue, 14 Nov 2017 09:34:03 +0000 (17:34 +0800)
Signed-off-by: Yao Zongyou <yaozongyou@vip.qq.com>
src/tools/rados/rados.cc

index eb2dd24b57a0945531d24b9ff7d9b9f31abbf90b..0709d923a4f0c323f93c168f4e4dad708f8845bf 100644 (file)
@@ -96,6 +96,7 @@ void usage(ostream& out)
 "   rmxattr <obj-name> attr\n"
 "   stat <obj-name>                  stat the named object\n"
 "   stat2 <obj-name>                 stat2 the named object (with high precision time)\n"
+"   touch <obj-name> [timestamp]     change the named object modification time\n"
 "   mapext <obj-name>\n"
 "   rollback <obj-name> <snap-name>  roll back object to snap <snap-name>\n"
 "\n"
@@ -2269,6 +2270,31 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
       cout << pool_name << "/" << oid
           << " mtime " << t << ", size " << size << std::endl;
     }
+  } 
+  else if (strcmp(nargs[0], "touch") == 0) {
+    if (!pool_name || nargs.size() < 2)
+      usage_exit();
+    string oid(nargs[1]);
+    time_t timestamp = time(NULL);
+    if (nargs.size() > 2) {
+      char* endptr = NULL;
+      timestamp = static_cast<time_t>(strtoll(nargs[2], &endptr, 10));
+      if (*endptr) {
+        cerr << "Invalid value for timestamp: '" << nargs[2] << "'" << std::endl;
+        ret = -EINVAL;
+        goto out;
+      }
+    }
+    
+    ObjectWriteOperation op;
+    op.create(false);
+    op.mtime(&timestamp);
+    ret = io_ctx.operate(oid, &op);
+    if (ret < 0) {
+      cerr << " error touch-ing " << pool_name << "/" << oid << ": "
+          << cpp_strerror(ret) << std::endl;
+      goto out;
+    }
   }
   else if (strcmp(nargs[0], "get") == 0) {
     if (!pool_name || nargs.size() < 3)