mirror of
https://github.com/minio/minio-rs.git
synced 2026-01-22 15:42:10 +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::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)?;
|
||||||
|
|
||||||
|
|||||||
@ -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(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user