Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Fix panic on partition error
Browse files Browse the repository at this point in the history
- Ignore partitions that cause errors, instead of panicking due to a nil
dereference
- Fixes errors caused by insufficient permissions of certain devices
  • Loading branch information
cjbassi committed Dec 8, 2018
1 parent 83bb121 commit d712195
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/widgets/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (self *Disk) update() {
if strings.HasPrefix(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,
Expand All @@ -75,7 +76,7 @@ func (self *Disk) update() {

// delete a partition if it no longer exists
todelete := []string{}
for key, _ := range self.Partitions {
for key := range self.Partitions {
exists := false
for _, Part := range Partitions {
device := strings.Replace(Part.Device, "/dev/", "", -1)
Expand All @@ -97,6 +98,7 @@ func (self *Disk) update() {
usage, err := psDisk.Usage(Part.Mount)
if err != nil {
log.Printf("failed to get partition usage statistics from gopsutil: %v. Part: %v", err, Part)
continue
}
Part.UsedPercent = int(usage.UsedPercent)

Expand All @@ -106,6 +108,7 @@ func (self *Disk) update() {
ret, err := psDisk.IOCounters("/dev/" + Part.Device)
if err != nil {
log.Printf("failed to get partition read/write info from gopsutil: %v. Part: %v", err, Part)
continue
}
data := ret[Part.Device]
curRead, curWrite := data.ReadBytes, data.WriteBytes
Expand Down

0 comments on commit d712195

Please sign in to comment.