From 6237f6e5d3ab9e4d3444442e63fc8dbc4b14c9ca Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Sat, 4 May 2024 15:02:00 +0000 Subject: [PATCH] update --- system/disk.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/system/disk.go b/system/disk.go index 4a7581e..d990448 100644 --- a/system/disk.go +++ b/system/disk.go @@ -53,8 +53,32 @@ func getDiskInfo() (string, string, string, error) { lines := strings.Split(string(output), "\n") if len(lines) >= 2 { fields := strings.Split(strings.TrimSpace(lines[1]), " ") - if len(fields) > 0 && fields[0] != "" { - bootPath = fields[0] + var nonEmptyFields []string + for _, field := range fields { + if field != "" { + nonEmptyFields = append(nonEmptyFields, field) + } + } + if len(nonEmptyFields) > 0 && nonEmptyFields[0] != "" { + bootPath = nonEmptyFields[0] + if strings.Contains(bootPath, "overlay") && len(nonEmptyFields) >= 5 { + tpDiskTotal, err1 := strconv.Atoi(nonEmptyFields[1]) + tpDiskUsage, err2 := strconv.Atoi(nonEmptyFields[2]) + if err1 == nil && err2 == nil { + diskTotalGB = float64(tpDiskTotal) / (1024 * 1024) + diskUsageGB = float64(tpDiskUsage) / (1024 * 1024) + if diskTotalGB < 1 { + diskTotalStr = strconv.FormatFloat(diskTotalGB*1024, 'f', 2, 64) + " MB" + " [" + nonEmptyFields[4] + "]" + } else { + diskTotalStr = strconv.FormatFloat(diskTotalGB, 'f', 2, 64) + " GB" + " [" + nonEmptyFields[4] + "]" + } + if diskUsageGB < 1 { + diskUsageStr = strconv.FormatFloat(diskUsageGB*1024, 'f', 2, 64) + " MB" + } else { + diskUsageStr = strconv.FormatFloat(diskUsageGB, 'f', 2, 64) + " GB" + } + } + } } } }