refactor: move object operation contracts (#3559)

This commit is contained in:
安正超
2026-06-18 09:48:13 +08:00
committed by GitHub
parent 3fb4cb3d65
commit e5cad7ed20
34 changed files with 529 additions and 200 deletions
+1
View File
@@ -26,5 +26,6 @@ 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, ListOperations, ObjectInfoOrErr};
pub use object::{MultipartOperations, ObjectIO, ObjectOperations};
pub use object::{ObjectPreconditionError, ObjectPreconditionPart, ObjectPreconditionState};
pub use object::{VersionMarker, WalkOptions, WalkVersionsSortOrder};
+185
View File
@@ -180,6 +180,106 @@ impl<Filter> Default for WalkOptions<Filter> {
}
}
#[async_trait::async_trait]
pub trait ObjectIO: Send + Sync + fmt::Debug + 'static {
type Error: std::error::Error + Send + Sync + 'static;
type RangeSpec: Send + 'static;
type HeaderMap: Send + 'static;
type ObjectOptions: Send + Sync + 'static;
type ObjectInfo: Send + 'static;
type GetObjectReader: Send + 'static;
type PutObjectReader: Send + 'static;
async fn get_object_reader(
&self,
bucket: &str,
object: &str,
range: Option<Self::RangeSpec>,
h: Self::HeaderMap,
opts: &Self::ObjectOptions,
) -> Result<Self::GetObjectReader, Self::Error>;
async fn put_object(
&self,
bucket: &str,
object: &str,
data: &mut Self::PutObjectReader,
opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
}
#[async_trait::async_trait]
#[allow(clippy::too_many_arguments)]
pub trait ObjectOperations: Send + Sync + fmt::Debug {
type Error: std::error::Error + Send + Sync + 'static;
type ObjectInfo: Send + 'static;
type ObjectOptions: Send + Sync + 'static;
type FileInfo: Send + Sync + 'static;
type ObjectToDelete: Send + 'static;
type DeletedObject: Send + 'static;
async fn get_object_info(
&self,
bucket: &str,
object: &str,
opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
async fn verify_object_integrity(&self, bucket: &str, object: &str, opts: &Self::ObjectOptions) -> Result<(), Self::Error>;
async fn copy_object(
&self,
src_bucket: &str,
src_object: &str,
dst_bucket: &str,
dst_object: &str,
src_info: &mut Self::ObjectInfo,
src_opts: &Self::ObjectOptions,
dst_opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
async fn delete_object_version(
&self,
bucket: &str,
object: &str,
fi: &Self::FileInfo,
force_del_marker: bool,
) -> Result<(), Self::Error>;
async fn delete_object(&self, bucket: &str, object: &str, opts: Self::ObjectOptions)
-> Result<Self::ObjectInfo, Self::Error>;
async fn delete_objects(
&self,
bucket: &str,
objects: Vec<Self::ObjectToDelete>,
opts: Self::ObjectOptions,
) -> (Vec<Self::DeletedObject>, Vec<Option<Self::Error>>);
async fn put_object_metadata(
&self,
bucket: &str,
object: &str,
opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
async fn get_object_tags(&self, bucket: &str, object: &str, opts: &Self::ObjectOptions) -> Result<String, Self::Error>;
async fn put_object_tags(
&self,
bucket: &str,
object: &str,
tags: &str,
opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
async fn delete_object_tags(
&self,
bucket: &str,
object: &str,
opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
async fn add_partial(&self, bucket: &str, object: &str, version_id: &str) -> Result<(), Self::Error>;
async fn transition_object(&self, bucket: &str, object: &str, opts: &Self::ObjectOptions) -> Result<(), Self::Error>;
async fn restore_transitioned_object(
self: Arc<Self>,
bucket: &str,
object: &str,
opts: &Self::ObjectOptions,
) -> Result<(), Self::Error>;
}
#[async_trait::async_trait]
#[allow(clippy::too_many_arguments)]
pub trait ListOperations: Send + Sync + fmt::Debug {
@@ -223,6 +323,91 @@ pub trait ListOperations: Send + Sync + fmt::Debug {
) -> Result<(), Self::Error>;
}
#[async_trait::async_trait]
#[allow(clippy::too_many_arguments)]
pub trait MultipartOperations: Send + Sync + fmt::Debug {
type Error: std::error::Error + Send + Sync + 'static;
type ObjectInfo: Send + 'static;
type ObjectOptions: Send + Sync + 'static;
type PutObjectReader: Send + 'static;
type CompletePart: Send + 'static;
type ListMultipartsInfo: Send + 'static;
type MultipartUploadResult: Send + 'static;
type PartInfo: Send + 'static;
type MultipartInfo: Send + 'static;
type ListPartsInfo: Send + 'static;
async fn list_multipart_uploads(
&self,
bucket: &str,
prefix: &str,
key_marker: Option<String>,
upload_id_marker: Option<String>,
delimiter: Option<String>,
max_uploads: usize,
) -> Result<Self::ListMultipartsInfo, Self::Error>;
async fn new_multipart_upload(
&self,
bucket: &str,
object: &str,
opts: &Self::ObjectOptions,
) -> Result<Self::MultipartUploadResult, Self::Error>;
async fn copy_object_part(
&self,
src_bucket: &str,
src_object: &str,
dst_bucket: &str,
dst_object: &str,
upload_id: &str,
part_id: usize,
start_offset: i64,
length: i64,
src_info: &Self::ObjectInfo,
src_opts: &Self::ObjectOptions,
dst_opts: &Self::ObjectOptions,
) -> Result<(), Self::Error>;
async fn put_object_part(
&self,
bucket: &str,
object: &str,
upload_id: &str,
part_id: usize,
data: &mut Self::PutObjectReader,
opts: &Self::ObjectOptions,
) -> Result<Self::PartInfo, Self::Error>;
async fn get_multipart_info(
&self,
bucket: &str,
object: &str,
upload_id: &str,
opts: &Self::ObjectOptions,
) -> Result<Self::MultipartInfo, Self::Error>;
async fn list_object_parts(
&self,
bucket: &str,
object: &str,
upload_id: &str,
part_number_marker: Option<usize>,
max_parts: usize,
opts: &Self::ObjectOptions,
) -> Result<Self::ListPartsInfo, Self::Error>;
async fn abort_multipart_upload(
&self,
bucket: &str,
object: &str,
upload_id: &str,
opts: &Self::ObjectOptions,
) -> Result<(), Self::Error>;
async fn complete_multipart_upload(
self: Arc<Self>,
bucket: &str,
object: &str,
upload_id: &str,
uploaded_parts: Vec<Self::CompletePart>,
opts: &Self::ObjectOptions,
) -> Result<Self::ObjectInfo, Self::Error>;
}
#[derive(Debug, Default)]
pub struct ListObjectsInfo<ObjectItem> {
pub is_truncated: bool,