diff --git a/ecstore/src/bucket_meta.rs b/ecstore/src/bucket_meta.rs index f089de50d..aedeb9cf7 100644 --- a/ecstore/src/bucket_meta.rs +++ b/ecstore/src/bucket_meta.rs @@ -10,24 +10,24 @@ pub const BUCKET_METADATA_FILE: &str = ".metadata.bin"; pub const BUCKET_METADATA_FORMAT: u16 = 1; pub const BUCKET_METADATA_VERSION: u16 = 1; -#[derive(Debug, PartialEq, Deserialize, Serialize)] +#[derive(Debug, PartialEq, Deserialize, Serialize, Default)] pub struct BucketMetadata { format: u16, version: u16, pub name: String, - pub created: OffsetDateTime, + pub created: Option, } -impl Default for BucketMetadata { - fn default() -> Self { - Self { - format: Default::default(), - version: Default::default(), - name: Default::default(), - created: OffsetDateTime::now_utc(), - } - } -} +// impl Default for BucketMetadata { +// fn default() -> Self { +// Self { +// format: Default::default(), +// version: Default::default(), +// name: Default::default(), +// created: OffsetDateTime::now_utc(), +// } +// } +// } impl BucketMetadata { pub fn new(name: &str) -> Self { diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 08b0d9a4c..66b24181a 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -28,7 +28,7 @@ pub struct LocalDisk { pub _format_meta: Option, pub _format_path: PathBuf, // pub format_legacy: bool, // drop - pub _format_last_check: OffsetDateTime, + pub _format_last_check: Option, } impl LocalDisk { @@ -48,7 +48,7 @@ impl LocalDisk { let mut id = Uuid::nil(); // let mut format_legacy = false; - let mut format_last_check = OffsetDateTime::UNIX_EPOCH; + let mut format_last_check = None; if !format_data.is_empty() { let s = format_data.as_slice(); @@ -61,7 +61,7 @@ impl LocalDisk { id = fm.erasure.this; // format_legacy = fm.erasure.distribution_algo == DistributionAlgoVersion::V1; - format_last_check = OffsetDateTime::now_utc(); + format_last_check = Some(OffsetDateTime::now_utc()); } let disk = Self { @@ -619,8 +619,11 @@ impl DiskAPI for LocalDisk { let name = entry.file_name().to_string_lossy().to_string(); let created = match metadata.created() { - Ok(md) => OffsetDateTime::from(md), - Err(_) => return Err(Error::msg("Not supported created on this platform")), + Ok(md) => Some(OffsetDateTime::from(md)), + Err(_) => { + warn!("Not supported created on this platform"); + None + } }; volumes.push(VolumeInfo { name, created }); @@ -634,8 +637,11 @@ impl DiskAPI for LocalDisk { let m = read_file_metadata(&p).await?; let modtime = match m.modified() { - Ok(md) => OffsetDateTime::from(md), - Err(_) => return Err(Error::msg("Not supported modified on this platform")), + Ok(md) => Some(OffsetDateTime::from(md)), + Err(_) => { + warn!("Not supported modified on this platform"); + None + } }; Ok(VolumeInfo { @@ -722,8 +728,11 @@ impl DiskAPI for LocalDisk { res.exists = true; res.data = data; res.mod_time = match meta.modified() { - Ok(md) => OffsetDateTime::from(md), - Err(_) => return Err(Error::msg("Not supported modified on this platform")), + Ok(md) => Some(OffsetDateTime::from(md)), + Err(_) => { + warn!("Not supported modified on this platform"); + None + } }; results.push(res); diff --git a/ecstore/src/disk/mod.rs b/ecstore/src/disk/mod.rs index 17377a08c..57e0498eb 100644 --- a/ecstore/src/disk/mod.rs +++ b/ecstore/src/disk/mod.rs @@ -107,7 +107,7 @@ pub struct ReadMultipleReq { pub max_results: usize, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct ReadMultipleResp { pub bucket: String, pub prefix: String, @@ -115,26 +115,26 @@ pub struct ReadMultipleResp { pub exists: bool, pub error: String, pub data: Vec, - pub mod_time: OffsetDateTime, + pub mod_time: Option, } -impl Default for ReadMultipleResp { - fn default() -> Self { - Self { - bucket: String::new(), - prefix: String::new(), - file: String::new(), - exists: false, - error: String::new(), - data: Vec::new(), - mod_time: OffsetDateTime::UNIX_EPOCH, - } - } -} +// impl Default for ReadMultipleResp { +// fn default() -> Self { +// Self { +// bucket: String::new(), +// prefix: String::new(), +// file: String::new(), +// exists: false, +// error: String::new(), +// data: Vec::new(), +// mod_time: OffsetDateTime::UNIX_EPOCH, +// } +// } +// } pub struct VolumeInfo { pub name: String, - pub created: OffsetDateTime, + pub created: Option, } pub struct ReadOptions { diff --git a/ecstore/src/store_api.rs b/ecstore/src/store_api.rs index b601a66b0..f5ccc4b41 100644 --- a/ecstore/src/store_api.rs +++ b/ecstore/src/store_api.rs @@ -19,7 +19,7 @@ pub struct FileInfo { pub deleted: bool, // DataDir of the file pub data_dir: Uuid, - pub mod_time: OffsetDateTime, + pub mod_time: Option, pub size: usize, pub data: Option>, pub fresh: bool, // indicates this is a first time call to write FileInfo. @@ -58,7 +58,7 @@ impl FileInfo { Ok(t) } - pub fn add_object_part(&mut self, num: usize, part_size: usize, mod_time: OffsetDateTime, actual_size: usize) { + pub fn add_object_part(&mut self, num: usize, part_size: usize, mod_time: Option, actual_size: usize) { let part = ObjectPartInfo { number: num, size: part_size, @@ -120,7 +120,7 @@ impl Default for FileInfo { erasure: Default::default(), deleted: Default::default(), data_dir: Uuid::nil(), - mod_time: OffsetDateTime::UNIX_EPOCH, + mod_time: None, size: Default::default(), data: Default::default(), fresh: Default::default(), @@ -175,27 +175,27 @@ impl FileInfo { } } -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)] pub struct ObjectPartInfo { // pub etag: Option, pub number: usize, pub size: usize, pub actual_size: usize, // 源数据大小 - pub mod_time: OffsetDateTime, + pub mod_time: Option, // pub index: Option>, // pub checksums: Option>, } -impl Default for ObjectPartInfo { - fn default() -> Self { - Self { - number: Default::default(), - size: Default::default(), - mod_time: OffsetDateTime::UNIX_EPOCH, - actual_size: Default::default(), - } - } -} +// impl Default for ObjectPartInfo { +// fn default() -> Self { +// Self { +// number: Default::default(), +// size: Default::default(), +// mod_time: OffsetDateTime::UNIX_EPOCH, +// actual_size: Default::default(), +// } +// } +// } pub struct RawFileInfo { pub buf: Vec, @@ -358,30 +358,30 @@ impl HTTPRangeSpec { } } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct ObjectOptions { // Use the maximum parity (N/2), used when saving server configuration files pub max_parity: bool, - pub mod_time: OffsetDateTime, + pub mod_time: Option, pub part_number: usize, } -impl Default for ObjectOptions { - fn default() -> Self { - Self { - max_parity: Default::default(), - mod_time: OffsetDateTime::UNIX_EPOCH, - part_number: Default::default(), - } - } -} +// impl Default for ObjectOptions { +// fn default() -> Self { +// Self { +// max_parity: Default::default(), +// mod_time: OffsetDateTime::UNIX_EPOCH, +// part_number: Default::default(), +// } +// } +// } pub struct BucketOptions {} #[derive(Debug, Clone)] pub struct BucketInfo { pub name: String, - pub created: OffsetDateTime, + pub created: Option, } pub struct MultipartUploadResult { @@ -390,7 +390,7 @@ pub struct MultipartUploadResult { pub struct PartInfo { pub part_num: usize, - pub last_mod: OffsetDateTime, + pub last_mod: Option, pub size: usize, } @@ -415,7 +415,7 @@ pub struct ObjectInfo { pub data_blocks: usize, pub version_id: Uuid, pub deleted: bool, - pub mod_time: OffsetDateTime, + pub mod_time: Option, pub size: usize, pub parts: Vec, pub is_latest: bool, diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index d860ab312..1c2912427 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -20,7 +20,6 @@ use s3s::S3; use s3s::{S3Request, S3Response}; use std::fmt::Debug; use std::str::FromStr; -use time::OffsetDateTime; use transform_stream::AsyncTryStream; use ecstore::error::Result; @@ -145,11 +144,7 @@ impl S3 for FS { let range = HTTPRangeSpec::nil(); let h = HeaderMap::new(); - let opts = &ObjectOptions { - max_parity: false, - mod_time: OffsetDateTime::UNIX_EPOCH, - part_number: 0, - }; + let opts = &ObjectOptions::default(); let reader = try_!( self.store @@ -160,12 +155,12 @@ impl S3 for FS { let info = reader.object_info; let content_type = try_!(ContentType::from_str("application/x-msdownload")); - let last_modified = Timestamp::from(info.mod_time); + let last_modified = info.mod_time.map(|v| Timestamp::from(v)); let output = GetObjectOutput { body: Some(reader.stream), content_length: Some(info.size as i64), - last_modified: Some(last_modified), + last_modified: last_modified, content_type: Some(content_type), ..Default::default() }; @@ -199,12 +194,12 @@ impl S3 for FS { debug!("info {:?}", info); let content_type = try_!(ContentType::from_str("application/x-msdownload")); - let last_modified = Timestamp::from(info.mod_time); + let last_modified = info.mod_time.map(|v| Timestamp::from(v)); let output = HeadObjectOutput { content_length: Some(try_!(i64::try_from(info.size))), content_type: Some(content_type), - last_modified: Some(last_modified), + last_modified: last_modified, // metadata: object_metadata, ..Default::default() }; @@ -220,7 +215,7 @@ impl S3 for FS { let buckets: Vec = bucket_infos .iter() .map(|v| Bucket { - creation_date: Some(Timestamp::from(v.created)), + creation_date: v.created.map(|v| Timestamp::from(v)), name: Some(v.name.clone()), }) .collect();