Fix Unmatched checksum error (#1585)

Fixed #1575

Always consume the stream if a `data_verifier` is provided in
`binstalk_download::Download`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2024-01-21 16:50:20 +10:00 committed by GitHub
parent 7f70a4e8ee
commit 01ddf00b54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -201,18 +201,17 @@ impl Download<'_> {
debug!("Downloading and extracting then in-memory processing");
match extract_tar_based_stream_and_visit(&mut stream, fmt, visitor).await {
Ok(()) => {
debug!("Download, extraction and in-memory procession OK");
Ok(())
}
Err(err) => {
if has_data_verifier {
consume_stream(&mut stream).await;
}
Err(err)
}
let res = extract_tar_based_stream_and_visit(&mut stream, fmt, visitor).await;
if has_data_verifier {
consume_stream(&mut stream).await;
}
if res.is_ok() {
debug!("Download, extraction and in-memory procession OK");
}
res
}
/// Download a file from the provided URL and extract it to the provided path.
@ -242,18 +241,15 @@ impl Download<'_> {
PkgFmtDecomposed::Zip => extract_zip(&mut stream, path).await,
};
match res {
Ok(extracted_files) => {
debug!("Download OK, extracted to: '{}'", path.display());
Ok(extracted_files)
}
Err(err) => {
if has_data_verifier {
consume_stream(&mut stream).await;
}
Err(err)
}
if has_data_verifier {
consume_stream(&mut stream).await;
}
if res.is_ok() {
debug!("Download OK, extracted to: '{}'", path.display());
}
res
}
inner(self, fmt, path.as_ref()).await