From 3e54acbc20c52a749586978e2111c55dbef1a2b6 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 9 Feb 2015 18:16:13 -0800 Subject: [PATCH] rgw: encode rgw_obj::orig_obj We weren't encoding orig_obj, however, it's now needed so that we can call get_index_key() on decoded objects. Only encode/decode it if ns or instance are not empty. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index e96d916f814b..5949195cdf71 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1266,7 +1266,7 @@ public: /* * get the object's key name as being referred to by the bucket index. */ - string get_index_key_name() { + string get_index_key_name() const { if (ns.empty()) { if (orig_obj.size() < 1 || orig_obj[0] != '_') { return orig_obj; @@ -1279,7 +1279,7 @@ public: return string(buf) + orig_obj; }; - void get_index_key(rgw_obj_key *key) { + void get_index_key(rgw_obj_key *key) const { key->name = get_index_key_name(); key->instance = instance; } @@ -1375,17 +1375,20 @@ public: } void encode(bufferlist& bl) const { - ENCODE_START(4, 3, bl); + ENCODE_START(5, 3, bl); ::encode(bucket.name, bl); ::encode(loc, bl); ::encode(ns, bl); ::encode(object, bl); ::encode(bucket, bl); ::encode(instance, bl); + if (!ns.empty() || !instance.empty()) { + ::encode(orig_obj, bl); + } ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START_LEGACY_COMPAT_LEN(4, 3, 3, bl); + DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, bl); ::decode(bucket.name, bl); ::decode(loc, bl); ::decode(ns, bl); @@ -1394,6 +1397,19 @@ public: ::decode(bucket, bl); if (struct_v >= 4) ::decode(instance, bl); + if (ns.empty() && instance.empty()) { + orig_obj = object; + } else { + if (struct_v >= 5) { + ::decode(orig_obj, bl); + } else { + ssize_t pos = object.find('_', 1); + if (pos < 0) { + throw buffer::error(); + } + orig_obj = object.substr(pos); + } + } DECODE_FINISH(bl); } void dump(Formatter *f) const; -- 2.47.3