From 27ab5e27e1e2b581ed16b47733c54ebf2e053648 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Mon, 25 May 2020 18:44:46 -0500 Subject: [PATCH] Fix progress printing NaN --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9502d69..b36db43 100644 --- a/src/main.rs +++ b/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 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); easy.url(url.as_str()); @@ -89,13 +89,17 @@ fn download_command(backup: model::anime_boxes::Backup, mut config: config::Conf bytes_downloaded, total_bytes_to_upload, 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(); stdout.queue(cursor::SavePosition); stdout.write( format!( - "\n{} {}: {:.2}\n", - &progress_count, progress_filename, percentage + "{}: {:.2}% {}", + progress_filename, percentage, &progress_count ) .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) { Err(e) => { - println!("Error writing to {:#?}: {}%", target_path, e); + println!("Error writing to {:#?}: {}", target_path, e); Err(WriteError::Pause) } Ok(d) => Ok(data.len()),