Skip to content

Commit

Permalink
Make bucket cache resilient to partial downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Jun 11, 2024
1 parent 4072f18 commit 9825893
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/soroban-cli/src/commands/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use io_tee::TeeReader;
use soroban_ledger_snapshot::LedgerSnapshot;
use std::{
collections::HashSet,
fs::OpenOptions,
fs::{self, OpenOptions},
io::{self, BufReader, Read},
path::PathBuf,
str::FromStr,
Expand Down Expand Up @@ -209,6 +209,7 @@ impl Cmd {
let contract_ids = self.contract_ids.clone();
let wasm_hashes = self.wasm_hashes.clone();
(seen, snapshot) = tokio::task::spawn_blocking(move || {
let dl_path = cache_path.with_extension("dl");
let buf = BufReader::new(read);
let read: Box<dyn Read + Sync + Send> = if gz {
let gz = GzDecoder::new(buf);
Expand All @@ -217,7 +218,7 @@ impl Cmd {
.create(true)
.truncate(true)
.write(true)
.open(&cache_path)
.open(&dl_path)
.unwrap();
let tee = TeeReader::new(buf, file);
Box::new(tee)
Expand Down Expand Up @@ -274,6 +275,9 @@ impl Cmd {
}
}
}
if gz {
fs::rename(&dl_path, &cache_path).unwrap();
}
if count_saved > 0 {
println!("🔎 Found {count_saved} entries");
}
Expand Down

0 comments on commit 9825893

Please sign in to comment.