bool LCRule::validate()
{
- if (id.length() > MAX_ID_LEN)
+ if (id.length() > MAX_ID_LEN) {
return false;
- else if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0)
- return false;
- else if (expiration.get_days() <= 0)
+ }
+ else if (expiration.get_days() <= 0) {
return false;
+ }
return true;
}
prefix_map[rule->get_prefix()] = rule->get_expiration().get_days();
}
-bool RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule)
+int RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule)
{
- if (!rule->validate())
- return false;
+ if (!rule->validate()) {
+ return -EINVAL;
+ }
string id;
rule->get_id(id);
- if (rule_map.find(id) != rule_map.end()) //id shouldn't be the same
- return false;
+ if (rule_map.find(id) != rule_map.end()) { //id shouldn't be the same
+ return -EINVAL;
+ }
rule_map.insert(pair<string, LCRule>(id, *rule));
auto ret = prefix_map.insert(pair<string, int>(rule->get_prefix(), rule->get_expiration().get_days()));
//Now prefix shouldn't be the same. When we add noncurrent expiration or other action, prefix may be same.
- if (!ret.second)
- return false;
- return true;
+ if (!ret.second) {
+ return -ERR_INVALID_REQUEST;
+ }
+ return 0;
}
//Rules are conflicted: if one rule's prefix starts with other rule's prefix, and these two rules
//define same action(now only support expiration days).
bool RGWLifecycleConfiguration::validate()
{
- if (prefix_map.size() < 2)
+ if (prefix_map.size() < 2) {
return true;
+ }
auto next_iter = prefix_map.begin();
auto cur_iter = next_iter++;
while (next_iter != prefix_map.end()) {
if (!lc_status)
return false;
status = lc_status->get_data();
+ if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0)
+ return false;
lc_expiration = static_cast<LCExpiration_S3 *>(find_first("Expiration"));
if (!lc_expiration)
int RGWLifecycleConfiguration_S3::rebuild(RGWRados *store, RGWLifecycleConfiguration& dest)
{
+ int ret = 0;
multimap<string, LCRule>::iterator iter;
for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
LCRule& src_rule = iter->second;
- if (!dest.check_and_add_rule(&src_rule))
- return -EINVAL;
+ ret = dest.check_and_add_rule(&src_rule);
+ if (ret < 0)
+ return ret;
+ }
+ if (!dest.validate()) {
+ ret = -ERR_INVALID_REQUEST;
}
- if (!dest.validate())
- return -EINVAL;
- return 0;
+ return ret;
}
void RGWLifecycleConfiguration_S3::dump_xml(Formatter *f) const
ldout(s->cct, 15) << "read len=" << len << " data=" << (data ? data : "") << dendl;
if (!parser.parse(data, len, 1)) {
- op_ret = -EINVAL;
+ op_ret = -ERR_MALFORMED_XML;
return;
}
config = static_cast<RGWLifecycleConfiguration_S3 *>(parser.find_first("LifecycleConfiguration"));
if (!config) {
- op_ret = -EINVAL;
+ op_ret = -ERR_MALFORMED_XML;
return;
}