Skip to content

Commit

Permalink
Merge pull request #186 from okudajun/for-issue-185
Browse files Browse the repository at this point in the history
Fix the wrong type i32 used for offset calculation at download to u64
  • Loading branch information
zmrow committed Aug 8, 2022
2 parents 4da4aeb + a41ce77 commit 502594e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,20 @@ impl SnapshotDownloader {
.await
.context(error::OpenFileSnafu { path })?;

let offset = context.block_index * block_size;
let offset = u64::try_from(offset).with_context(|_| error::ConvertNumberSnafu {
what: "file offset",
number: offset.to_string(),
target: "u64",
})?;
// Calculate the offset to write the block into the target file
let block_index_u64 =
u64::try_from(context.block_index).with_context(|_| error::ConvertNumberSnafu {
what: "block index",
number: context.block_index.to_string(),
target: "u64",
})?;
let block_size_u64 =
u64::try_from(block_size).with_context(|_| error::ConvertNumberSnafu {
what: "block size",
number: block_size.to_string(),
target: "u64",
})?;
let offset = block_index_u64 * block_size_u64;

f.seek(SeekFrom::Start(offset))
.await
Expand Down

0 comments on commit 502594e

Please sign in to comment.