]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rgw_obj encoding fixes
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 10 Sep 2015 19:52:43 +0000 (12:52 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 27 Sep 2016 23:03:07 +0000 (16:03 -0700)
Fix a few issues:
 - conversion to and from rgw_obj_key
 - strip_namespace_from_object() in the case where object starts
   with underscore
 - encoding if object has either namespace or instance and starts
   with underscore

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.h

index d05e3167adb15011c7a54697a355f03380d567f4..b20739545dc165b2ebff1919b06ad6799621b064 100644 (file)
@@ -933,6 +933,10 @@ struct rgw_obj_key {
     set(n, i);
   }
 
+  rgw_obj_key(const cls_rgw_obj_key& k) {
+    set(k);
+  }
+
   void set(const cls_rgw_obj_key& k) {
     name = k.name;
     instance = k.instance;
@@ -1181,8 +1185,7 @@ public:
     init(b, o);
   }
   rgw_obj(rgw_bucket& b, const rgw_obj_key& k) : in_extra_data(false) {
-    init(b, k.name);
-    set_instance(k.instance);
+    from_index_key(b, k);
   }
   void init(rgw_bucket& b, const std::string& o) {
     bucket = b;
@@ -1291,6 +1294,29 @@ public:
     return string(buf) + orig_obj;
   };
 
+  void from_index_key(rgw_bucket& b, const rgw_obj_key& key) {
+    if (key.name[0] != '_') {
+      init(b, key.name);
+      set_instance(key.instance);
+      return;
+    }
+    if (key.name[1] == '_') {
+      init(b, key.name.substr(1));
+      set_instance(key.instance);
+      return;
+    }
+    ssize_t pos = key.name.find('_', 1);
+    if (pos < 0) {
+      /* shouldn't happen, just use key */
+      init(b, key.name);
+      set_instance(key.instance);
+      return;
+    }
+
+    init_ns(b, key.name.substr(pos + 1), key.name.substr(1, pos -1));
+    set_instance(key.instance);
+  }
+
   void get_index_key(rgw_obj_key *key) const {
     key->name = get_index_key_name();
     key->instance = instance;
@@ -1381,6 +1407,11 @@ public:
       return false;
     }
 
+    if (obj[1] == '_') {
+      obj = obj.substr(1);
+      return true;
+    }
+
     size_t period_pos = obj.find('.');
     if (period_pos < pos) {
       return false;
@@ -1425,7 +1456,11 @@ public:
     if (struct_v >= 4)
       ::decode(instance, bl);
     if (ns.empty() && instance.empty()) {
-      orig_obj = object;
+      if (object[0] != '_') {
+        orig_obj = object;
+      } else {
+       orig_obj = object.substr(1);
+      }
     } else {
       if (struct_v >= 5) {
         ::decode(orig_obj, bl);