Accept list of items in list_objects() callback. (#16)

Signed-off-by: Bala.FA <bala@minio.io>
This commit is contained in:
Bala FA 2022-08-25 00:19:28 +05:30 committed by GitHub
parent 1888666d4f
commit b62b39e7c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 68 deletions

View File

@ -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)?;

View File

@ -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);
}
}

View File

@ -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(),