mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-07-25 15:26:37 +00:00
fix #4638: proxmox-backup-client: status: guard against div by zero
We throw an error if the value for total is zero. Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
parent
73bd988c42
commit
dae0b67f1f
@ -1590,9 +1590,12 @@ async fn status(param: Value) -> Result<Value, Error> {
|
|||||||
let v = v.as_u64().unwrap();
|
let v = v.as_u64().unwrap();
|
||||||
let total = record["total"].as_u64().unwrap();
|
let total = record["total"].as_u64().unwrap();
|
||||||
let roundup = total / 200;
|
let roundup = total / 200;
|
||||||
let per = ((v + roundup) * 100) / total;
|
if let Some(per) = ((v + roundup) * 100).checked_div(total) {
|
||||||
let info = format!(" ({} %)", per);
|
let info = format!(" ({} %)", per);
|
||||||
Ok(format!("{} {:>8}", v, info))
|
Ok(format!("{} {:>8}", v, info))
|
||||||
|
} else {
|
||||||
|
bail!("Cannot render total percentage: denominator is zero");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let options = default_table_format_options()
|
let options = default_table_format_options()
|
||||||
|
Loading…
Reference in New Issue
Block a user