follow the psutil principles, do nothing if can not find root device

This commit is contained in:
arstercz 2022-05-01 02:33:09 +00:00
parent d52b97cd25
commit f6dc96c30e
1 changed files with 3 additions and 4 deletions

View File

@ -349,12 +349,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
// /dev/root is not the real device name
// so we get the real device name from its major/minor number
if d.Device == "/dev/root" && d.Fstype != "nfs" {
if d.Device == "/dev/root" {
devpath, err := os.Readlink(common.HostSys("/dev/block/" + blockDeviceID))
if err != nil {
return nil, err
if err == nil {
d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1)
}
d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1)
}
}
ret = append(ret, d)