From 7e9de44b3aeb0a74a459d9c587699791e2c7dd2a Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Sun, 9 Dec 2018 21:11:03 -0800 Subject: [PATCH] Cleanup logic to trim 'dev' from disk partition --- src/widgets/disk.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/widgets/disk.go b/src/widgets/disk.go index 8a7e8c13..c3a85f67 100644 --- a/src/widgets/disk.go +++ b/src/widgets/disk.go @@ -60,15 +60,14 @@ func (self *Disk) update() { // add partition if it's new for _, Part := range Partitions { - device := strings.Replace(Part.Device, "/dev/", "", -1) // don't show loop devices - if strings.HasPrefix(device, "loop") { + if strings.HasPrefix(Part.Device, "loop") { continue } // check if partition doesn't already exist in our list - if _, ok := self.Partitions[device]; !ok { - self.Partitions[device] = &Partition{ - Device: device, + if _, ok := self.Partitions[Part.Device]; !ok { + self.Partitions[Part.Device] = &Partition{ + Device: Part.Device, Mount: Part.Mountpoint, } } @@ -79,8 +78,7 @@ func (self *Disk) update() { for key := range self.Partitions { exists := false for _, Part := range Partitions { - device := strings.Replace(Part.Device, "/dev/", "", -1) - if key == device { + if key == Part.Device { exists = true break } @@ -105,7 +103,7 @@ func (self *Disk) update() { Free, Mag := utils.ConvertBytes(usage.Free) Part.Free = fmt.Sprintf("%3d%s", uint64(Free), Mag) - ret, err := psDisk.IOCounters("/dev/" + Part.Device) + ret, err := psDisk.IOCounters(Part.Device) if err != nil { log.Printf("failed to get partition read/write info from gopsutil: %v. Part: %v", err, Part) continue @@ -139,7 +137,7 @@ func (self *Disk) update() { for i, key := range sortedPartitions { Part := self.Partitions[key] self.Rows[i] = make([]string, 6) - self.Rows[i][0] = Part.Device + self.Rows[i][0] = strings.Replace(Part.Device, "/dev/", "", -1) self.Rows[i][1] = Part.Mount self.Rows[i][2] = fmt.Sprintf("%d%%", Part.UsedPercent) self.Rows[i][3] = Part.Free