diff --git a/core/src/services/oss/lister.rs b/core/src/services/oss/lister.rs index a130ea201b56..e69096e50db2 100644 --- a/core/src/services/oss/lister.rs +++ b/core/src/services/oss/lister.rs @@ -102,6 +102,7 @@ impl oio::PageList for OssLister { } let mut meta = Metadata::new(EntryMode::from_path(&path)); + meta.set_is_current(true); meta.set_etag(&object.etag); meta.set_content_md5(object.etag.trim_matches('"')); meta.set_content_length(object.size); diff --git a/core/src/services/s3/lister.rs b/core/src/services/s3/lister.rs index 9063e610448d..fb27f23ee5bc 100644 --- a/core/src/services/s3/lister.rs +++ b/core/src/services/s3/lister.rs @@ -124,7 +124,7 @@ impl oio::PageList for S3Lister { } let mut meta = Metadata::new(EntryMode::from_path(&path)); - + meta.set_is_current(true); if let Some(etag) = &object.etag { meta.set_etag(etag); meta.set_content_md5(etag.trim_matches('"')); @@ -239,6 +239,7 @@ impl oio::PageList for S3ObjectVersionsLister { let mut meta = Metadata::new(EntryMode::from_path(&path)); meta.set_version(&version_object.version_id); + meta.set_is_current(version_object.is_latest); meta.set_content_length(version_object.size); meta.set_last_modified(parse_datetime_from_rfc3339( version_object.last_modified.as_str(), diff --git a/core/src/types/metadata.rs b/core/src/types/metadata.rs index c1d4155e1971..fb9fbe92335d 100644 --- a/core/src/types/metadata.rs +++ b/core/src/types/metadata.rs @@ -43,6 +43,7 @@ pub struct Metadata { etag: Option, last_modified: Option>, version: Option, + is_current: Option, user_metadata: Option>, } @@ -64,6 +65,7 @@ impl Metadata { content_disposition: None, version: None, user_metadata: None, + is_current: None, } } @@ -404,6 +406,35 @@ impl Metadata { self } + /// Determines if the provided metadata reflects the current status of the path. + /// + /// - `Ok(true)` indicates it is the latest status. + /// - `Ok(false)` indicates it is an older version of the file. + /// - `None` indicates uncertainty about its status. + /// + /// This API allows users to verify if the version is up-to-date when listing with versions. + pub fn is_current(&self) -> Option { + self.is_current + } + + /// Set the `is_current` status of this entry. + /// + /// By default, this value will be `None`. Please avoid using this API if it's unclear whether the entry is current. + /// Set it to `true` if it is known to be the latest; otherwise, set it to `false`. + pub fn with_is_current(mut self, is_current: Option) -> Self { + self.is_current = is_current; + self + } + + /// Set the `is_current` status of this entry. + /// + /// By default, this value will be `None`. Please avoid using this API if it's unclear whether the entry is current. + /// Set it to `true` if it is known to be the latest; otherwise, set it to `false`. + pub fn set_is_current(&mut self, is_current: bool) -> &mut Self { + self.is_current = Some(is_current); + self + } + /// User defined metadata of this entry /// /// The prefix of the user defined metadata key(for example: in oss, it's x-oss-meta-)