From cf7a930d3986bb592caee91d72994f67fd7f57e9 Mon Sep 17 00:00:00 2001 From: weisd Date: Tue, 1 Jul 2025 17:26:47 +0800 Subject: [PATCH] todo --- ecstore/src/bucket/metadata_sys.rs | 2 +- ecstore/src/disk/fs.rs | 7 --- ecstore/src/disk/os.rs | 3 +- rustfs/src/admin/handlers/bucket_meta.rs | 61 ++++++++++++++++++------ 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/ecstore/src/bucket/metadata_sys.rs b/ecstore/src/bucket/metadata_sys.rs index 333f5900..a9efd66d 100644 --- a/ecstore/src/bucket/metadata_sys.rs +++ b/ecstore/src/bucket/metadata_sys.rs @@ -56,7 +56,7 @@ pub async fn set_bucket_metadata(bucket: String, bm: BucketMetadata) -> Result<( Ok(()) } -pub(crate) async fn get(bucket: &str) -> Result> { +pub async fn get(bucket: &str) -> Result> { let sys = get_bucket_metadata_sys()?; let lock = sys.read().await; lock.get(bucket).await diff --git a/ecstore/src/disk/fs.rs b/ecstore/src/disk/fs.rs index 07475e07..f083e6d3 100644 --- a/ecstore/src/disk/fs.rs +++ b/ecstore/src/disk/fs.rs @@ -5,8 +5,6 @@ use tokio::{ io, }; -pub const SLASH_SEPARATOR: &str = "/"; - #[cfg(not(windows))] pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool { use std::os::unix::fs::MetadataExt; @@ -522,9 +520,4 @@ mod tests { // Should be different files assert!(!same_file(&metadata1, &metadata2)); } - - #[test] - fn test_slash_separator() { - assert_eq!(SLASH_SEPARATOR, "/"); - } } diff --git a/ecstore/src/disk/os.rs b/ecstore/src/disk/os.rs index 6158c1d4..67df445b 100644 --- a/ecstore/src/disk/os.rs +++ b/ecstore/src/disk/os.rs @@ -5,6 +5,7 @@ use std::{ use super::error::Result; use crate::disk::error_conv::to_file_error; +use rustfs_utils::path::SLASH_SEPARATOR; use tokio::fs; use tracing::warn; @@ -90,7 +91,7 @@ pub async fn read_dir(path: impl AsRef, count: i32) -> std::io::Result { - let config = match metadata_sys::get_notification_config(&bucket.name).await { - Ok(Some(res)) => res, - Err(e) => { - if e == StorageError::ConfigNotFound { - continue; + let config: s3s::dto::NotificationConfiguration = + match metadata_sys::get_notification_config(&bucket.name).await { + Ok(Some(res)) => res, + Err(e) => { + if e == StorageError::ConfigNotFound { + continue; + } + return Err(s3_error!(InternalError, "get bucket metadata failed: {e}")); } - return Err(s3_error!(InternalError, "get bucket metadata failed: {e}")); - } - Ok(None) => continue, - }; + Ok(None) => continue, + }; let config_xml = serialize(&config).map_err(|e| s3_error!(InternalError, "serialize config failed: {e}"))?; @@ -407,6 +413,8 @@ impl Operation for ImportBucketMetadata { return Err(s3_error!(InvalidRequest, "object store not init")); }; + let update_at = OffsetDateTime::now_utc(); + // Second pass: process file contents for (file_path, content) in file_contents { let file_path_split = file_path.split(SLASH_SEPARATOR).collect::>(); @@ -439,10 +447,35 @@ impl Operation for ImportBucketMetadata { bucket_metadatas.insert(bucket_name.to_string(), metadata.clone()); } - if conf_name == BUCKET_POLICY_CONFIG { - let _config: policy::policy::BucketPolicy = - serde_json::from_slice(&content).map_err(|e| s3_error!(InternalError, "deserialize config failed: {e}"))?; - // TODO: Apply the configuration + match conf_name { + BUCKET_POLICY_CONFIG => { + let config: policy::policy::BucketPolicy = match serde_json::from_slice(&content) { + Ok(config) => config, + Err(e) => { + warn!("deserialize config failed: {e}"); + continue; + } + }; + + if config.version.is_empty() { + continue; + } + + // let mut metadata = bucket_metadatas.get_mut(bucket_name).unwrap().clone(); + // metadata.policy_config_json = content; + // metadata.policy_config_updated_at = update_at; + } + BUCKET_NOTIFICATION_CONFIG => { + if let Err(e) = deserialize::(&content) { + warn!("deserialize config failed: {e}"); + continue; + } + + // let mut metadata = bucket_metadatas.get_mut(bucket_name).unwrap().clone(); + // metadata.notification_config_xml = content; + // metadata.notification_config_updated_at = update_at; + } + _ => {} } }