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::error::Error;
use crate::s3::sse::{Sse, SseCustomerKey}; 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::{ use crate::s3::utils::{
check_bucket_name, merge, to_http_header_value, to_iso8601utc, urlencode, Multimap, UtcTime, 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 recursive: bool,
pub use_api_v1: bool, pub use_api_v1: bool,
pub include_versions: 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> { impl<'a> ListObjectsArgs<'a> {
pub fn new( pub fn new(
bucket_name: &'a str, 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> { ) -> Result<ListObjectsArgs<'a>, Error> {
check_bucket_name(bucket_name, true)?; check_bucket_name(bucket_name, true)?;

View File

@ -1217,70 +1217,28 @@ impl<'a> Client<'a> {
let mut stop = false; let mut stop = false;
while !stop { while !stop {
if args.include_versions { if args.include_versions {
let resp = self.list_object_versions(&lov_args).await; let resp = self.list_object_versions(&lov_args).await?;
match resp { stop = !resp.is_truncated;
Ok(v) => { if resp.is_truncated {
if v.is_truncated { lov_args.key_marker = resp.next_key_marker;
lov_args.key_marker = v.next_key_marker; lov_args.version_id_marker = resp.next_version_id_marker;
lov_args.version_id_marker = v.next_version_id_marker; }
} else { stop = stop || !(args.result_fn)(resp.contents);
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(());
}
};
} else if args.use_api_v1 { } else if args.use_api_v1 {
let resp = self.list_objects_v1(&lov1_args).await; let resp = self.list_objects_v1(&lov1_args).await?;
match resp { stop = !resp.is_truncated;
Ok(v) => { if resp.is_truncated {
if v.is_truncated { lov1_args.marker = resp.next_marker;
lov1_args.marker = v.next_marker; }
} else { stop = stop || !(args.result_fn)(resp.contents);
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(());
}
};
} else { } else {
let resp = self.list_objects_v2(&lov2_args).await; let resp = self.list_objects_v2(&lov2_args).await?;
match resp { stop = !resp.is_truncated;
Ok(v) => { if resp.is_truncated {
if v.is_truncated { lov2_args.start_after = resp.start_after;
lov2_args.start_after = v.start_after; lov2_args.continuation_token = resp.next_continuation_token;
lov2_args.continuation_token = v.next_continuation_token; }
} else { stop = stop || !(args.result_fn)(resp.contents);
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(());
}
};
} }
} }

View File

@ -293,9 +293,10 @@ impl<'a> ClientTest<'a> {
self.client self.client
.list_objects( .list_objects(
&mut ListObjectsArgs::new(&self.test_bucket, &|res| { &mut ListObjectsArgs::new(&self.test_bucket, &|items| {
let item = res.unwrap(); for item in items.iter() {
assert_eq!(names.contains(&item.name), true); assert_eq!(names.contains(&item.name), true);
}
true true
}) })
.unwrap(), .unwrap(),