}
}
private boolean updateLifecycleRule(List<Rule> rules, String prefix)
{
Rule rule = null;
for (BucketLifecycleConfiguration.Rule lcRule : rules)
{
if (lcRule.getPrefix().equals(prefix))
{
rule = lcRule;
break;
}
}
if (rule == null && config.getBackupRetentionDays() <= 0)
return false;
if (rule != null && rule.getExpirationInDays() == config.getBackupRetentionDays())
{
logger.info("Cleanup rule already set");
return false;
}
if (rule == null)
{
// Create a new rule
rule = new BucketLifecycleConfiguration.Rule().withExpirationInDays(config.getBackupRetentionDays()).withPrefix(prefix);
rule.setStatus(BucketLifecycleConfiguration.ENABLED);
rule.setId(prefix);
rules.add(rule);
logger.info(String.format("Setting cleanup for %s to %d days", rule.getPrefix(), rule.getExpirationInDays()));
}
else if (config.getBackupRetentionDays() > 0)
{
logger.info(String.format("Setting cleanup for %s to %d days", rule.getPrefix(), config.getBackupRetentionDays()));
rule.setExpirationInDays(config.getBackupRetentionDays());
}
else
{
logger.info(String.format("Removing cleanup rule for %s", rule.getPrefix()));
rules.remove(rule);
}
return true;
}