mirror of
https://github.com/minio/minio-rs.git
synced 2025-12-06 15:26:51 +08:00
Accept list of items in list_objects() callback. (#16)
Signed-off-by: Bala.FA <bala@minio.io>
This commit is contained in:
parent
1888666d4f
commit
b62b39e7c9
@ -15,7 +15,7 @@
|
||||
|
||||
use crate::s3::error::Error;
|
||||
use crate::s3::sse::{Sse, SseCustomerKey};
|
||||
use crate::s3::types::{DeleteObject, Item, Part, Retention, SelectProgress, SelectRequest};
|
||||
use crate::s3::types::{DeleteObject, Item, Part, Retention, SelectRequest};
|
||||
use crate::s3::utils::{
|
||||
check_bucket_name, merge, to_http_header_value, to_iso8601utc, urlencode, Multimap, UtcTime,
|
||||
};
|
||||
@ -908,13 +908,13 @@ pub struct ListObjectsArgs<'a> {
|
||||
pub recursive: bool,
|
||||
pub use_api_v1: bool,
|
||||
pub include_versions: bool,
|
||||
pub result_fn: &'a dyn Fn(Result<&Item, Error>) -> bool,
|
||||
pub result_fn: &'a dyn Fn(Vec<Item>) -> bool,
|
||||
}
|
||||
|
||||
impl<'a> ListObjectsArgs<'a> {
|
||||
pub fn new(
|
||||
bucket_name: &'a str,
|
||||
result_fn: &'a dyn Fn(Result<&Item, Error>) -> bool,
|
||||
result_fn: &'a dyn Fn(Vec<Item>) -> bool,
|
||||
) -> Result<ListObjectsArgs<'a>, Error> {
|
||||
check_bucket_name(bucket_name, true)?;
|
||||
|
||||
|
||||
@ -1217,70 +1217,28 @@ impl<'a> Client<'a> {
|
||||
let mut stop = false;
|
||||
while !stop {
|
||||
if args.include_versions {
|
||||
let resp = self.list_object_versions(&lov_args).await;
|
||||
match resp {
|
||||
Ok(v) => {
|
||||
if v.is_truncated {
|
||||
lov_args.key_marker = v.next_key_marker;
|
||||
lov_args.version_id_marker = v.next_version_id_marker;
|
||||
} else {
|
||||
stop = true;
|
||||
}
|
||||
for item in v.contents.iter() {
|
||||
if !(args.result_fn)(Ok(item)) {
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
(args.result_fn)(Err(e));
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let resp = self.list_object_versions(&lov_args).await?;
|
||||
stop = !resp.is_truncated;
|
||||
if resp.is_truncated {
|
||||
lov_args.key_marker = resp.next_key_marker;
|
||||
lov_args.version_id_marker = resp.next_version_id_marker;
|
||||
}
|
||||
stop = stop || !(args.result_fn)(resp.contents);
|
||||
} else if args.use_api_v1 {
|
||||
let resp = self.list_objects_v1(&lov1_args).await;
|
||||
match resp {
|
||||
Ok(v) => {
|
||||
if v.is_truncated {
|
||||
lov1_args.marker = v.next_marker;
|
||||
} else {
|
||||
stop = true;
|
||||
}
|
||||
for item in v.contents.iter() {
|
||||
if !(args.result_fn)(Ok(item)) {
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
(args.result_fn)(Err(e));
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let resp = self.list_objects_v1(&lov1_args).await?;
|
||||
stop = !resp.is_truncated;
|
||||
if resp.is_truncated {
|
||||
lov1_args.marker = resp.next_marker;
|
||||
}
|
||||
stop = stop || !(args.result_fn)(resp.contents);
|
||||
} else {
|
||||
let resp = self.list_objects_v2(&lov2_args).await;
|
||||
match resp {
|
||||
Ok(v) => {
|
||||
if v.is_truncated {
|
||||
lov2_args.start_after = v.start_after;
|
||||
lov2_args.continuation_token = v.next_continuation_token;
|
||||
} else {
|
||||
stop = true;
|
||||
}
|
||||
for item in v.contents.iter() {
|
||||
if !(args.result_fn)(Ok(item)) {
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
(args.result_fn)(Err(e));
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let resp = self.list_objects_v2(&lov2_args).await?;
|
||||
stop = !resp.is_truncated;
|
||||
if resp.is_truncated {
|
||||
lov2_args.start_after = resp.start_after;
|
||||
lov2_args.continuation_token = resp.next_continuation_token;
|
||||
}
|
||||
stop = stop || !(args.result_fn)(resp.contents);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -293,9 +293,10 @@ impl<'a> ClientTest<'a> {
|
||||
|
||||
self.client
|
||||
.list_objects(
|
||||
&mut ListObjectsArgs::new(&self.test_bucket, &|res| {
|
||||
let item = res.unwrap();
|
||||
assert_eq!(names.contains(&item.name), true);
|
||||
&mut ListObjectsArgs::new(&self.test_bucket, &|items| {
|
||||
for item in items.iter() {
|
||||
assert_eq!(names.contains(&item.name), true);
|
||||
}
|
||||
true
|
||||
})
|
||||
.unwrap(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user