Merge pull request #521 from rustfs/feature-fix/ilm

fix
This commit is contained in:
安正超
2025-06-30 21:05:11 +08:00
committed by GitHub
2 changed files with 18 additions and 19 deletions
+6 -12
View File
@@ -161,7 +161,7 @@ pub trait Lifecycle {
async fn has_transition(&self) -> bool; async fn has_transition(&self) -> bool;
fn has_expiry(&self) -> bool; fn has_expiry(&self) -> bool;
async fn has_active_rules(&self, prefix: &str) -> bool; async fn has_active_rules(&self, prefix: &str) -> bool;
async fn validate(&self, lr: &ObjectLockConfiguration) -> Result<(), std::io::Error>; async fn validate(&self, lr_retention: bool) -> Result<(), std::io::Error>;
async fn filter_rules(&self, obj: &ObjectOpts) -> Option<Vec<LifecycleRule>>; async fn filter_rules(&self, obj: &ObjectOpts) -> Option<Vec<LifecycleRule>>;
async fn eval(&self, obj: &ObjectOpts) -> Event; async fn eval(&self, obj: &ObjectOpts) -> Event;
async fn eval_inner(&self, obj: &ObjectOpts, now: OffsetDateTime) -> Event; async fn eval_inner(&self, obj: &ObjectOpts, now: OffsetDateTime) -> Event;
@@ -242,7 +242,7 @@ impl Lifecycle for BucketLifecycleConfiguration {
false false
} }
async fn validate(&self, lr: &ObjectLockConfiguration) -> Result<(), std::io::Error> { async fn validate(&self, lr_retention: bool) -> Result<(), std::io::Error> {
if self.rules.len() > 1000 { if self.rules.len() > 1000 {
return Err(std::io::Error::other(ERR_LIFECYCLE_TOO_MANY_RULES)); return Err(std::io::Error::other(ERR_LIFECYCLE_TOO_MANY_RULES));
} }
@@ -252,17 +252,11 @@ impl Lifecycle for BucketLifecycleConfiguration {
for r in &self.rules { for r in &self.rules {
r.validate()?; r.validate()?;
if let Some(object_lock_enabled) = lr.object_lock_enabled.as_ref() { if let Some(expiration) = r.expiration.as_ref() {
if let Some(expiration) = r.expiration.as_ref() { if let Some(expired_object_delete_marker) = expiration.expired_object_delete_marker {
if let Some(expired_object_delete_marker) = expiration.expired_object_delete_marker { if lr_retention && (!expired_object_delete_marker) {
if object_lock_enabled.as_str() == ObjectLockEnabled::ENABLED && (!expired_object_delete_marker) { return Err(std::io::Error::other(ERR_LIFECYCLE_BUCKET_LOCKED));
return Err(std::io::Error::other(ERR_LIFECYCLE_BUCKET_LOCKED));
}
} /*else {
if object_lock_enabled.as_str() == ObjectLockEnabled::ENABLED {
return Err(Error::msg(ERR_LIFECYCLE_BUCKET_LOCKED));
} }
}*/
} }
} }
} }
+12 -7
View File
@@ -1715,20 +1715,25 @@ impl S3 for FS {
.. ..
} = req.input; } = req.input;
let mut lr_retention = false;
let rcfg = metadata_sys::get_object_lock_config(&bucket).await; let rcfg = metadata_sys::get_object_lock_config(&bucket).await;
if rcfg.is_err() { if let Ok(rcfg) = rcfg {
return Err(S3Error::with_message( if let Some(rule) = rcfg.0.rule {
S3ErrorCode::Custom("BucketLockIsNotExist".into()), if let Some(retention) = rule.default_retention {
"bucket lock is not exist.", if let Some(mode) = retention.mode {
)); if mode == ObjectLockRetentionMode::from_static(ObjectLockRetentionMode::GOVERNANCE) {
lr_retention = true;
}
}
}
}
} }
let rcfg = rcfg.expect("get_lifecycle_config err!").0;
//info!("lifecycle_configuration: {:?}", &lifecycle_configuration); //info!("lifecycle_configuration: {:?}", &lifecycle_configuration);
let Some(input_cfg) = lifecycle_configuration else { return Err(s3_error!(InvalidArgument)) }; let Some(input_cfg) = lifecycle_configuration else { return Err(s3_error!(InvalidArgument)) };
if let Err(err) = input_cfg.validate(&rcfg).await { if let Err(err) = input_cfg.validate(lr_retention).await {
//return Err(S3Error::with_message(S3ErrorCode::Custom("BucketLockValidateFailed".into()), "bucket lock validate failed.")); //return Err(S3Error::with_message(S3ErrorCode::Custom("BucketLockValidateFailed".into()), "bucket lock validate failed."));
return Err(S3Error::with_message(S3ErrorCode::Custom("ValidateFailed".into()), err.to_string())); return Err(S3Error::with_message(S3ErrorCode::Custom("ValidateFailed".into()), err.to_string()));
} }