refactor: move object list helper contracts (#3546)

This commit is contained in:
安正超
2026-06-18 06:09:33 +08:00
committed by GitHub
parent 87a3d107d6
commit 54bbd05b25
9 changed files with 113 additions and 43 deletions
+1
View File
@@ -25,3 +25,4 @@ pub use bucket::{BucketInfo, BucketOperations, BucketOptions, DeleteBucketOption
pub use error::{StorageErrorCode, StorageResult};
pub use multipart::{CompletePart, ListMultipartsInfo, ListPartsInfo, MultipartInfo, MultipartUploadResult, PartInfo};
pub use object::{HTTPPreconditions, HTTPRangeError, HTTPRangeSpec, ObjectLockRetentionOptions};
pub use object::{VersionMarker, WalkVersionsSortOrder};
+43
View File
@@ -14,6 +14,9 @@
use std::fmt;
use time::OffsetDateTime;
use uuid::Uuid;
const NULL_VERSION_MARKER: &str = "null";
#[derive(Debug, Default, Clone)]
pub struct HTTPPreconditions {
@@ -40,6 +43,30 @@ pub struct ObjectLockRetentionOptions {
pub bypass_governance: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VersionMarker {
Null,
Version(Uuid),
}
impl VersionMarker {
pub fn parse(marker: impl AsRef<str>) -> Result<Self, uuid::Error> {
let marker = marker.as_ref();
if marker == NULL_VERSION_MARKER {
Ok(Self::Null)
} else {
Ok(Self::Version(Uuid::parse_str(marker)?))
}
}
}
#[derive(Clone, Default, PartialEq, Eq)]
pub enum WalkVersionsSortOrder {
#[default]
Ascending,
Descending,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HTTPRangeError {
InvalidRangeSpec(String),
@@ -183,6 +210,22 @@ mod tests {
assert!(!opts.bypass_governance);
}
#[test]
fn version_marker_parses_null_and_uuid_markers() {
assert_eq!(VersionMarker::parse("null").expect("null marker should parse"), VersionMarker::Null);
let marker = "550e8400-e29b-41d4-a716-446655440000";
assert_eq!(
VersionMarker::parse(marker).expect("uuid marker should parse"),
VersionMarker::Version(Uuid::parse_str(marker).expect("test uuid should parse"))
);
}
#[test]
fn walk_versions_sort_order_defaults_to_ascending() {
assert!(matches!(WalkVersionsSortOrder::default(), WalkVersionsSortOrder::Ascending));
}
#[test]
fn http_range_spec_offset_length_handles_suffix_and_bounds() {
let range = HTTPRangeSpec {