aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-03-21 15:04:46 +0100
committerGitHub <noreply@github.com>2022-03-21 15:04:46 +0100
commite034db16bf68c06c1ecf63addd033fcbd83090e3 (patch)
tree5d4841d92159494c0d74814ac64584ee7f118fbf /cmd
parent4282f565338fdbc0746208d4a879499a700a2f64 (diff)
parente3cc0717b219c76a417f88a7b905008ff851fab1 (diff)
downloadpodman-e034db16bf68c06c1ecf63addd033fcbd83090e3.tar.gz
podman-e034db16bf68c06c1ecf63addd033fcbd83090e3.tar.bz2
podman-e034db16bf68c06c1ecf63addd033fcbd83090e3.zip
Merge pull request #13575 from Luap99/percent
podman system df: fix percent calculation
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/system/df.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/cmd/podman/system/df.go b/cmd/podman/system/df.go
index b2325507a..49918487a 100644
--- a/cmd/podman/system/df.go
+++ b/cmd/podman/system/df.go
@@ -2,6 +2,7 @@ package system
import (
"fmt"
+ "math"
"os"
"strings"
"time"
@@ -288,6 +289,10 @@ func (d *dfSummary) Size() string {
}
func (d *dfSummary) Reclaimable() string {
- percent := int(float64(d.reclaimable)/float64(d.size)) * 100
+ percent := 0
+ // make sure to check this to prevent div by zero problems
+ if d.size > 0 {
+ percent = int(math.Round(float64(d.reclaimable) / float64(d.size) * float64(100)))
+ }
return fmt.Sprintf("%s (%d%%)", units.HumanSize(float64(d.reclaimable)), percent)
}