mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 15:16:56 +00:00
refactor: move object list response contracts (#3548)
This commit is contained in:
@@ -4,6 +4,11 @@ use rustfs_storage_api::{
|
||||
VersionMarker, WalkVersionsSortOrder,
|
||||
};
|
||||
|
||||
pub type ListObjectsInfo = rustfs_storage_api::ListObjectsInfo<ObjectInfo>;
|
||||
pub type ListObjectsV2Info = rustfs_storage_api::ListObjectsV2Info<ObjectInfo>;
|
||||
pub type ListObjectVersionsInfo = rustfs_storage_api::ListObjectVersionsInfo<ObjectInfo>;
|
||||
pub type ObjectInfoOrErr = rustfs_storage_api::ObjectInfoOrErr<ObjectInfo, Error>;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ObjectOptions {
|
||||
// Use the maximum parity (N/2), used when saving server configuration files
|
||||
@@ -708,50 +713,6 @@ fn versions_after_marker(file_infos: &rustfs_filemeta::FileInfoVersions, marker:
|
||||
.unwrap_or(&file_infos.versions)
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ListObjectsInfo {
|
||||
// Indicates whether the returned list objects response is truncated. A
|
||||
// value of true indicates that the list was truncated. The list can be truncated
|
||||
// if the number of objects exceeds the limit allowed or specified
|
||||
// by max keys.
|
||||
pub is_truncated: bool,
|
||||
|
||||
// When response is truncated (the IsTruncated element value in the response
|
||||
// is true), you can use the key name in this field as marker in the subsequent
|
||||
// request to get next set of objects.
|
||||
pub next_marker: Option<String>,
|
||||
|
||||
// List of objects info for this request.
|
||||
pub objects: Vec<ObjectInfo>,
|
||||
|
||||
// List of prefixes for this request.
|
||||
pub prefixes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ListObjectsV2Info {
|
||||
// Indicates whether the returned list objects response is truncated. A
|
||||
// value of true indicates that the list was truncated. The list can be truncated
|
||||
// if the number of objects exceeds the limit allowed or specified
|
||||
// by max keys.
|
||||
pub is_truncated: bool,
|
||||
|
||||
// When response is truncated (the IsTruncated element value in the response
|
||||
// is true), you can use the key name in this field as marker in the subsequent
|
||||
// request to get next set of objects.
|
||||
//
|
||||
// NOTE: This element is returned only if you have delimiter request parameter
|
||||
// specified.
|
||||
pub continuation_token: Option<String>,
|
||||
pub next_continuation_token: Option<String>,
|
||||
|
||||
// List of objects info for this request.
|
||||
pub objects: Vec<ObjectInfo>,
|
||||
|
||||
// List of prefixes for this request.
|
||||
pub prefixes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ObjectToDelete {
|
||||
pub object_name: String,
|
||||
@@ -805,15 +766,6 @@ impl DeletedObject {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ListObjectVersionsInfo {
|
||||
pub is_truncated: bool,
|
||||
pub next_marker: Option<String>,
|
||||
pub next_version_idmarker: Option<String>,
|
||||
pub objects: Vec<ObjectInfo>,
|
||||
pub prefixes: Vec<String>,
|
||||
}
|
||||
|
||||
type WalkFilter = fn(&FileInfo) -> bool;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
@@ -827,12 +779,6 @@ pub struct WalkOptions {
|
||||
pub include_free_versions: bool, // include persisted tier free-version cleanup records
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ObjectInfoOrErr {
|
||||
pub item: Option<ObjectInfo>,
|
||||
pub err: Option<Error>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -25,5 +25,6 @@ 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::{ListObjectVersionsInfo, ListObjectsInfo, ListObjectsV2Info, ObjectInfoOrErr};
|
||||
pub use object::{ObjectPreconditionError, ObjectPreconditionPart, ObjectPreconditionState};
|
||||
pub use object::{VersionMarker, WalkVersionsSortOrder};
|
||||
|
||||
@@ -154,6 +154,38 @@ pub enum WalkVersionsSortOrder {
|
||||
Descending,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ListObjectsInfo<ObjectItem> {
|
||||
pub is_truncated: bool,
|
||||
pub next_marker: Option<String>,
|
||||
pub objects: Vec<ObjectItem>,
|
||||
pub prefixes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ListObjectsV2Info<ObjectItem> {
|
||||
pub is_truncated: bool,
|
||||
pub continuation_token: Option<String>,
|
||||
pub next_continuation_token: Option<String>,
|
||||
pub objects: Vec<ObjectItem>,
|
||||
pub prefixes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ListObjectVersionsInfo<ObjectItem> {
|
||||
pub is_truncated: bool,
|
||||
pub next_marker: Option<String>,
|
||||
pub next_version_idmarker: Option<String>,
|
||||
pub objects: Vec<ObjectItem>,
|
||||
pub prefixes: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ObjectInfoOrErr<ObjectItem, ListError> {
|
||||
pub item: Option<ObjectItem>,
|
||||
pub err: Option<ListError>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum HTTPRangeError {
|
||||
InvalidRangeSpec(String),
|
||||
@@ -386,6 +418,40 @@ mod tests {
|
||||
assert!(matches!(WalkVersionsSortOrder::default(), WalkVersionsSortOrder::Ascending));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_list_response_contracts_default_to_empty_collections() {
|
||||
let v1 = ListObjectsInfo::<()>::default();
|
||||
assert!(!v1.is_truncated);
|
||||
assert!(v1.next_marker.is_none());
|
||||
assert!(v1.objects.is_empty());
|
||||
assert!(v1.prefixes.is_empty());
|
||||
|
||||
let v2 = ListObjectsV2Info::<()>::default();
|
||||
assert!(!v2.is_truncated);
|
||||
assert!(v2.continuation_token.is_none());
|
||||
assert!(v2.next_continuation_token.is_none());
|
||||
assert!(v2.objects.is_empty());
|
||||
assert!(v2.prefixes.is_empty());
|
||||
|
||||
let versions = ListObjectVersionsInfo::<()>::default();
|
||||
assert!(!versions.is_truncated);
|
||||
assert!(versions.next_marker.is_none());
|
||||
assert!(versions.next_version_idmarker.is_none());
|
||||
assert!(versions.objects.is_empty());
|
||||
assert!(versions.prefixes.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_info_or_err_keeps_optional_item_and_error_slots() {
|
||||
let item = ObjectInfoOrErr::<usize, &str> {
|
||||
item: Some(7),
|
||||
err: None,
|
||||
};
|
||||
|
||||
assert_eq!(item.item, Some(7));
|
||||
assert!(item.err.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_range_spec_offset_length_handles_suffix_and_bounds() {
|
||||
let range = HTTPRangeSpec {
|
||||
|
||||
Reference in New Issue
Block a user