mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-25 21:46:50 +00:00
refactor: move object list helper contracts (#3546)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use rustfs_storage_api::{HTTPPreconditions, ObjectLockRetentionOptions};
|
||||
use rustfs_storage_api::{HTTPPreconditions, ObjectLockRetentionOptions, VersionMarker, WalkVersionsSortOrder};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ObjectOptions {
|
||||
@@ -740,12 +740,6 @@ impl ObjectInfo {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum VersionMarker {
|
||||
Null,
|
||||
Version(Uuid),
|
||||
}
|
||||
|
||||
fn versions_after_marker(file_infos: &rustfs_filemeta::FileInfoVersions, marker: VersionMarker) -> &[FileInfo] {
|
||||
let marker_idx = match marker {
|
||||
VersionMarker::Null => file_infos.versions.iter().position(|version| version.version_id.is_none()),
|
||||
@@ -876,13 +870,6 @@ pub struct WalkOptions {
|
||||
pub include_free_versions: bool, // include persisted tier free-version cleanup records
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub enum WalkVersionsSortOrder {
|
||||
#[default]
|
||||
Ascending,
|
||||
Descending,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ObjectInfoOrErr {
|
||||
pub item: Option<ObjectInfo>,
|
||||
|
||||
@@ -23,8 +23,7 @@ use crate::error::{
|
||||
};
|
||||
use crate::set_disk::SetDisks;
|
||||
use crate::store_api::{
|
||||
ListObjectVersionsInfo, ListObjectsInfo, ObjectInfo, ObjectInfoOrErr, ObjectOperations, ObjectOptions, VersionMarker,
|
||||
WalkOptions, WalkVersionsSortOrder,
|
||||
ListObjectVersionsInfo, ListObjectsInfo, ObjectInfo, ObjectInfoOrErr, ObjectOperations, ObjectOptions, WalkOptions,
|
||||
};
|
||||
use crate::store_utils::is_reserved_or_invalid_bucket;
|
||||
use crate::{store::ECStore, store_api::ListObjectsV2Info};
|
||||
@@ -34,6 +33,7 @@ use rustfs_filemeta::{
|
||||
MetaCacheEntries, MetaCacheEntriesSorted, MetaCacheEntriesSortedResult, MetaCacheEntry, MetadataResolutionParams,
|
||||
merge_file_meta_versions,
|
||||
};
|
||||
use rustfs_storage_api::{VersionMarker, WalkVersionsSortOrder};
|
||||
use rustfs_utils::path::{self, SLASH_SEPARATOR, base_dir_from_prefix};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
@@ -201,11 +201,7 @@ fn list_metadata_resolution_params(bucket: String, listing_quorum: usize, versio
|
||||
}
|
||||
|
||||
fn parse_version_marker(marker: String) -> Result<VersionMarker> {
|
||||
if marker == "null" {
|
||||
Ok(VersionMarker::Null)
|
||||
} else {
|
||||
Ok(VersionMarker::Version(Uuid::parse_str(&marker)?))
|
||||
}
|
||||
Ok(VersionMarker::parse(marker)?)
|
||||
}
|
||||
|
||||
fn version_marker_for_entries(
|
||||
|
||||
@@ -31,6 +31,7 @@ doctest = false
|
||||
async-trait.workspace = true
|
||||
serde.workspace = true
|
||||
time.workspace = true
|
||||
uuid.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json.workspace = true
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user