Browse Source

Fix progress printing NaN

master
Drew Short 5 years ago
parent
commit
27ab5e27e1
  1. 14
      src/main.rs

14
src/main.rs

@ -79,7 +79,7 @@ fn download_command(backup: model::anime_boxes::Backup, mut config: config::Conf
let filename = path_segments.last().unwrap(); let filename = path_segments.last().unwrap();
let target_path = temp_directory.as_path().join(&filename); let target_path = temp_directory.as_path().join(&filename);
let progress_count = format!("{}/{}", count, to_download_count);
let progress_count = format!("{:}/{:}", count, to_download_count);
let progress_filename = String::from(filename); let progress_filename = String::from(filename);
easy.url(url.as_str()); easy.url(url.as_str());
@ -89,13 +89,17 @@ fn download_command(backup: model::anime_boxes::Backup, mut config: config::Conf
bytes_downloaded, bytes_downloaded,
total_bytes_to_upload, total_bytes_to_upload,
bytes_uploaded| { bytes_uploaded| {
let percentage = (bytes_downloaded / total_bytes_to_download) * 100.0;
let percentage = if bytes_downloaded <= 0.0 {
0.0
} else {
(bytes_downloaded / total_bytes_to_download) * 100.0
};
let mut stdout = stdout(); let mut stdout = stdout();
stdout.queue(cursor::SavePosition); stdout.queue(cursor::SavePosition);
stdout.write( stdout.write(
format!( format!(
"\n{} {}: {:.2}\n",
&progress_count, progress_filename, percentage
"{}: {:.2}% {}",
progress_filename, percentage, &progress_count
) )
.as_bytes(), .as_bytes(),
); );
@ -106,7 +110,7 @@ fn download_command(backup: model::anime_boxes::Backup, mut config: config::Conf
); );
match easy.write_function(move |data| match write_to_file(data, &target_path) { match easy.write_function(move |data| match write_to_file(data, &target_path) {
Err(e) => { Err(e) => {
println!("Error writing to {:#?}: {}%", target_path, e);
println!("Error writing to {:#?}: {}", target_path, e);
Err(WriteError::Pause) Err(WriteError::Pause)
} }
Ok(d) => Ok(data.len()), Ok(d) => Ok(data.len()),

Loading…
Cancel
Save