Skip to content

Commit 2eea435

Browse files
committed
FIX: Fix checksum for resumed download
1 parent 5af1441 commit 2eea435

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
## 0.37.0 - TBD
44

5-
#### Breaking changes
6-
- The `map_symbols` parameter for `SubmitJobParams::builder()` now defaults to `true` for JSON and CSV encodings
5+
### Breaking changes
6+
- Changed the default to `true` for the `map_symbols` parameter in
7+
`SubmitJobParams::builder()` for JSON and CSV encodings
8+
9+
### Bug fixes
10+
- Fixed checksum verification for resumed downloads in `batch().download()`. Previously,
11+
it would erroneously fail
712

813
## 0.36.0 - 2025-11-19
914

src/historical/batch.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use reqwest::RequestBuilder;
1616
use serde::{de, Deserialize, Deserializer};
1717
use sha2::{Digest, Sha256};
1818
use time::OffsetDateTime;
19-
use tokio::io::BufWriter;
19+
use tokio::{
20+
fs::File,
21+
io::{AsyncReadExt, BufWriter},
22+
};
2023
use tracing::{debug, error, info, info_span, warn, Instrument};
2124
use typed_builder::TypedBuilder;
2225

@@ -211,7 +214,7 @@ impl BatchClient<'_> {
211214
let mut retries = 0;
212215
'retry: loop {
213216
let mut req = self.inner.get_with_path(url.path())?;
214-
match Self::check_if_exists(path, exp_size).await? {
217+
match Self::check_if_exists(path, exp_size, &mut hasher).await? {
215218
Header::Skip => {
216219
return Ok(());
217220
}
@@ -261,7 +264,11 @@ impl BatchClient<'_> {
261264
.await
262265
}
263266

264-
async fn check_if_exists(path: &Path, exp_size: u64) -> crate::Result<Header> {
267+
async fn check_if_exists(
268+
path: &Path,
269+
exp_size: u64,
270+
hasher: &mut Option<Sha256>,
271+
) -> crate::Result<Header> {
265272
let Ok(metadata) = tokio::fs::metadata(path).await else {
266273
return Ok(Header::Range(None));
267274
};
@@ -273,6 +280,17 @@ impl BatchClient<'_> {
273280
total_bytes = exp_size,
274281
"Found existing file, resuming download"
275282
);
283+
if let Some(hasher) = hasher {
284+
let mut buf = vec![0; 1 << 23];
285+
let mut file = File::open(path).await?;
286+
loop {
287+
let read_size = file.read(&mut buf).await?;
288+
if read_size == 0 {
289+
break;
290+
}
291+
hasher.update(&buf[..read_size]);
292+
}
293+
}
276294
}
277295
Ordering::Equal => {
278296
debug!("Skipping download as file already exists and matches expected size");
@@ -299,7 +317,7 @@ impl BatchClient<'_> {
299317
if hash_hex != exp_hash_hex {
300318
warn!(
301319
hash_hex,
302-
exp_hash_hex, "Downloaded file failed checksum validation"
320+
exp_hash_hex, "Downloaded file failed checksum verification"
303321
);
304322
} else {
305323
debug!("Successfully verified checksum");

0 commit comments

Comments
 (0)