[pbs-devel] [PATCH proxmox-backup 2/2] fix division by zero

Dietmar Maurer dietmar at proxmox.com
Fri Jul 24 09:15:33 CEST 2020


Why do we use duration.as_secs() here?

We can do better by using floating point values using duration.as_secs_f64() to calculate
the speed more exactly.

> On 07/23/2020 6:16 PM Stoiko Ivanov <s.ivanov at proxmox.com> wrote:
> 
>  
> in case the backup duration gets rounded to 0 seconds
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/client/backup_writer.rs | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/src/client/backup_writer.rs b/src/client/backup_writer.rs
> index 7e5adb3c..c2db2e76 100644
> --- a/src/client/backup_writer.rs
> +++ b/src/client/backup_writer.rs
> @@ -264,9 +264,14 @@ impl BackupWriter {
>              crate::tools::format::strip_server_file_expenstion(archive_name.clone())
>          };
>          if archive_name != CATALOG_NAME {
> -            let speed: HumanByte = (uploaded / (duration.as_secs() as usize)).into();
> -            let uploaded: HumanByte = uploaded.into();
> -            println!("{}: had to upload {} from {} in {}s, avgerage speed {}/s).", archive, uploaded, vsize_h, duration.as_secs(), speed);
> +            let hb_uploaded: HumanByte = uploaded.into();
> +            match duration.as_secs() {
> +                0 => println!("{}: had to upload {} from {} in {}s", archive, hb_uploaded, vsize_h, duration.as_secs()),
> +                dur => {
> +                    let speed: HumanByte = (uploaded / (dur as usize)).into();
> +                    println!("{}: had to upload {} from {} in {}s, (average speed {}/s).", archive, hb_uploaded, vsize_h, duration.as_secs(), speed);
> +                }
> +            }
>          } else {
>              println!("Uploaded backup catalog ({})", vsize_h);
>          }
> -- 
> 2.20.1
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel





More information about the pbs-devel mailing list