From a96f352fa7021988d13321ec81fbda9e56c7c2ad Mon Sep 17 00:00:00 2001 From: likewu Date: Mon, 30 Jun 2025 18:16:15 +0800 Subject: [PATCH] fix --- ecstore/src/bucket/lifecycle/lifecycle.rs | 18 ++++++------------ rustfs/src/storage/ecfs.rs | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ecstore/src/bucket/lifecycle/lifecycle.rs b/ecstore/src/bucket/lifecycle/lifecycle.rs index 0d934387..2fd907d4 100644 --- a/ecstore/src/bucket/lifecycle/lifecycle.rs +++ b/ecstore/src/bucket/lifecycle/lifecycle.rs @@ -161,7 +161,7 @@ pub trait Lifecycle { async fn has_transition(&self) -> bool; fn has_expiry(&self) -> 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>; async fn eval(&self, obj: &ObjectOpts) -> Event; async fn eval_inner(&self, obj: &ObjectOpts, now: OffsetDateTime) -> Event; @@ -242,7 +242,7 @@ impl Lifecycle for BucketLifecycleConfiguration { 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 { return Err(std::io::Error::other(ERR_LIFECYCLE_TOO_MANY_RULES)); } @@ -252,17 +252,11 @@ impl Lifecycle for BucketLifecycleConfiguration { for r in &self.rules { 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(expired_object_delete_marker) = expiration.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)); - } - } /*else { - if object_lock_enabled.as_str() == ObjectLockEnabled::ENABLED { - return Err(Error::msg(ERR_LIFECYCLE_BUCKET_LOCKED)); + if let Some(expiration) = r.expiration.as_ref() { + if let Some(expired_object_delete_marker) = expiration.expired_object_delete_marker { + if lr_retention && (!expired_object_delete_marker) { + return Err(std::io::Error::other(ERR_LIFECYCLE_BUCKET_LOCKED)); } - }*/ } } } diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 07112ef2..14a2f64b 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -1715,20 +1715,25 @@ impl S3 for FS { .. } = req.input; + let mut lr_retention = false; let rcfg = metadata_sys::get_object_lock_config(&bucket).await; - if rcfg.is_err() { - return Err(S3Error::with_message( - S3ErrorCode::Custom("BucketLockIsNotExist".into()), - "bucket lock is not exist.", - )); + if let Ok(rcfg) = rcfg { + if let Some(rule) = rcfg.0.rule { + if let Some(retention) = rule.default_retention { + 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); 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("ValidateFailed".into()), err.to_string())); }