Skip to content

Commit

Permalink
Merge pull request #1 from espressif/skip-downloads
Browse files Browse the repository at this point in the history
skipping downloads if file already present and sha checksum checks
  • Loading branch information
Hahihula authored Jun 26, 2024
2 parents d4a5b96 + 0afc09c commit 36a8b28
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions src/wizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,42 @@ async fn download_tools(
let mut downloaded_tools: Vec<String> = vec![];
for (tool_name, download_link) in download_links.iter() {
println!("Downloading tool: {}", tool_name);
let progress_bar = ProgressBar::new(100);
let progress_bar = ProgressBar::new(download_link.size);
progress_bar.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})").unwrap()
.with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap())
.progress_chars("#>-"));

let update_progress = |amount_downloaded: u64, total_size: u64| {
let current_progress = ((amount_downloaded as f64) / (total_size as f64)) * 100.0;
progress_bar.set_position(current_progress as u64);
// let current_progress = ((amount_downloaded as f64) / (total_size as f64)) * 100.0;
progress_bar.set_position(amount_downloaded);
};
println!("Download link: {}", download_link);
println!("Download link: {}", download_link.url);
println!("destination: {}", destination_path);

match idf_im_lib::download_file(download_link, destination_path, &update_progress).await {
let file_path = Path::new(&download_link.url);
let filename: &str = file_path.file_name().unwrap().to_str().unwrap();

let full_file_path = Path::new(&destination_path).join(Path::new(filename));
match idf_im_lib::verify_file_checksum(
&download_link.sha256,
full_file_path.to_str().unwrap(),
) {
Ok(true) => {
downloaded_tools.push(filename.to_string()); // add it to the list for extraction even if it's already downloaded
println!("The file is already downloaded and the checksum matches.");
progress_bar.finish();
continue;
}
_ => {
println!("The checksum does not match or file was not avalible.");
// TODO: move to debug
}
}

match idf_im_lib::download_file(&download_link.url, destination_path, &update_progress)
.await
{
Ok(_) => {
let file_path = Path::new(download_link);
let filename: &str = file_path.file_name().unwrap().to_str().unwrap();
downloaded_tools.push(filename.to_string());
progress_bar.finish();
println!("Downloaded {}", tool_name);
Expand All @@ -220,7 +240,6 @@ async fn download_tools(
panic!();
}
}
// TODO: check sha256 of downloaded files
}
downloaded_tools
}
Expand Down

0 comments on commit 36a8b28

Please sign in to comment.