1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

Fixing calculation of UsedPercent.

Now it is calculated based of available disk space for user,
not including reserved space for root. This is compatible
with psutil and df command.
This commit is contained in:
Tomasz Kolodziej 2018-07-30 14:59:23 +02:00
parent c06610bac7
commit 573f3336a4

View File

@ -47,10 +47,11 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0
}
if ret.Total == 0 {
if (ret.Used + ret.Free) == 0 {
ret.UsedPercent = 0
} else {
ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0
ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0
}
return ret, nil