src/client/http_client.rs: use async for download_chunk_list
This commit is contained in:
parent
2f831baec0
commit
c2a5a9f353
@ -828,34 +828,27 @@ impl BackupClient {
|
|||||||
(verify_queue_tx, verify_result_rx)
|
(verify_queue_tx, verify_result_rx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_chunk_list(
|
async fn download_chunk_list(
|
||||||
h2: H2Client,
|
h2: H2Client,
|
||||||
path: &str,
|
path: &str,
|
||||||
archive_name: &str,
|
archive_name: &str,
|
||||||
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
||||||
) -> impl Future<Output = Result<(), Error>> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let param = json!({ "archive-name": archive_name });
|
let param = json!({ "archive-name": archive_name });
|
||||||
let request = H2Client::request_builder("localhost", "GET", path, Some(param)).unwrap();
|
let request = H2Client::request_builder("localhost", "GET", path, Some(param)).unwrap();
|
||||||
|
|
||||||
h2.send_request(request, None)
|
let h2request = h2.send_request(request, None).await?;
|
||||||
.and_then(move |response| {
|
let resp = h2request.await?;
|
||||||
response
|
|
||||||
.map_err(Error::from)
|
|
||||||
.and_then(move |resp| {
|
|
||||||
let status = resp.status();
|
let status = resp.status();
|
||||||
|
|
||||||
if !status.is_success() {
|
if !status.is_success() {
|
||||||
future::Either::Left(
|
H2Client::h2api_response(resp).await?; // raise error
|
||||||
H2Client::h2api_response(resp)
|
unreachable!();
|
||||||
.map(|_| Err(format_err!("unknown error")))
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
future::Either::Right(future::ok(resp.into_body()))
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.and_then(move |mut body| {
|
|
||||||
|
|
||||||
|
let mut body = resp.into_body();
|
||||||
let mut release_capacity = body.release_capacity().clone();
|
let mut release_capacity = body.release_capacity().clone();
|
||||||
|
|
||||||
DigestListDecoder::new(body.map_err(Error::from))
|
DigestListDecoder::new(body.map_err(Error::from))
|
||||||
@ -865,8 +858,7 @@ impl BackupClient {
|
|||||||
known_chunks.lock().unwrap().insert(chunk);
|
known_chunks.lock().unwrap().insert(chunk);
|
||||||
futures::future::ok(())
|
futures::future::ok(())
|
||||||
})
|
})
|
||||||
})
|
.await
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upload_chunk_info_stream(
|
fn upload_chunk_info_stream(
|
||||||
|
Loading…
Reference in New Issue
Block a user