Skip to content

Commit

Permalink
feat(core): Add is_current to metadata (#5493)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenbin1002 authored Jan 2, 2025
1 parent 6778dca commit 8549524
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/src/services/oss/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion core/src/services/s3/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('"'));
Expand Down Expand Up @@ -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(),
Expand Down
31 changes: 31 additions & 0 deletions core/src/types/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct Metadata {
etag: Option<String>,
last_modified: Option<DateTime<Utc>>,
version: Option<String>,
is_current: Option<bool>,

user_metadata: Option<HashMap<String, String>>,
}
Expand All @@ -64,6 +65,7 @@ impl Metadata {
content_disposition: None,
version: None,
user_metadata: None,
is_current: None,
}
}

Expand Down Expand Up @@ -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<bool> {
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<bool>) -> 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-)
Expand Down

0 comments on commit 8549524

Please sign in to comment.