* part of the given namespace, it returns false.
*/
static bool translate_raw_obj_to_obj_in_ns(string& obj, string& instance, string& ns) {
- if (ns.empty()) {
- if (obj[0] != '_')
- return true;
-
- if (obj.size() >= 2 && obj[1] == '_') {
- obj = obj.substr(1);
+ if (obj[0] != '_') {
+ if (ns.empty()) {
return true;
}
-
return false;
}
- if (obj[0] != '_' || obj.size() < 3) // for namespace, min size would be 3: _x_
- return false;
-
- int pos = obj.find('_', 1);
- if (pos <= 1) // if it starts with __, it's not in our namespace
- return false;
-
- string obj_ns = obj.substr(1, pos - 1);
- parse_ns_field(obj_ns, instance);
- if (obj_ns.compare(ns) != 0)
- return false;
+ string obj_ns;
+ bool ret = parse_raw_oid(obj, &obj, &instance, &obj_ns);
+ if (!ret) {
+ return ret;
+ }
- obj = obj.substr(pos + 1);
- return true;
+ return (ns == obj_ns);
}
static bool parse_raw_oid(const string& oid, string *obj_name, string *obj_instance, string *obj_ns) {
- obj_name->clear();
obj_instance->clear();
obj_ns->clear();
if (oid[0] != '_') {
ldout(store->ctx(), 20) << "obj entry: " << entry.key.name << " [" << entry.key.instance << "]" << dendl;
}
- /*
- * this is a bit confusing, but the list operation isn't going to return the namespace, for
- * the object, but it will return the instance. So we need to decode the namespace out of the
- * object key. The problem is that the list_op is mainly used to list objects in a specific
- * namespace, but we want to list all, that's why we have the special handling.
- */
- string obj_name;
- string obj_instance;
- string obj_ns;
- rgw_obj::parse_raw_oid(entry.key.name, &obj_name, &obj_instance, &obj_ns);
ldout(store->ctx(), 20) << __func__ << ": entry.key.name=" << entry.key.name << " entry.key.instance=" << entry.key.instance << " entry.ns=" << entry.ns << dendl;
- ldout(store->ctx(), 20) << __func__ << ": obj_name=" << obj_name << " obj_instance=" << obj_instance << " obj_ns=" << obj_ns << dendl;
- rgw_obj_key key(obj_name, entry.key.instance);
- rgw_obj obj(bucket_info.bucket, key);
- obj.set_ns(obj_ns);
+ rgw_obj obj(bucket_info.bucket, entry.key);
+ obj.set_ns(entry.ns);
RGWRados::Object op_target(store, bucket_info, obj_ctx, obj);
RGWObjEnt& entry = eiter->second;
rgw_obj_key key = obj;
string instance;
+ string ns;
- bool check_ns = rgw_obj::translate_raw_obj_to_obj_in_ns(obj.name, instance, params.ns);
+ bool valid = rgw_obj::parse_raw_oid(obj.name, &obj.name, &instance, &ns);
+ if (!valid) {
+ ldout(cct, 0) << "ERROR: could not parse object name: " << obj.name << dendl;
+ continue;
+ }
+ bool check_ns = (ns == params.ns);
if (!params.list_versions && !entry.is_visible()) {
continue;
}
RGWObjEnt ent = eiter->second;
ent.key = obj;
- ent.ns = params.ns;
+ ent.ns = ns;
result->push_back(ent);
count++;
}