From ab6db76df142372f09b79c80b37d02d97a9f2c59 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 7 Apr 2017 11:40:49 -0700 Subject: [PATCH] Fix IOCountersForNames on darwin --- disk/disk_darwin.go | 4 ---- disk/disk_darwin_cgo.go | 8 +++++++- disk/disk_darwin_nocgo.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/disk/disk_darwin.go b/disk/disk_darwin.go index 21ec491..dc642df 100644 --- a/disk/disk_darwin.go +++ b/disk/disk_darwin.go @@ -87,10 +87,6 @@ func Partitions(all bool) ([]PartitionStat, error) { return ret, nil } -func IOCountersForNames(names []string) (map[string]IOCountersStat, error) { - return nil, common.ErrNotImplementedError -} - func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { var _p0 unsafe.Pointer var bufsize uintptr diff --git a/disk/disk_darwin_cgo.go b/disk/disk_darwin_cgo.go index c8e8e65..99b401d 100644 --- a/disk/disk_darwin_cgo.go +++ b/disk/disk_darwin_cgo.go @@ -30,9 +30,11 @@ import ( "errors" "strings" "unsafe" + + "github.com/shirou/gopsutil/internal/common" ) -func IOCounters() (map[string]IOCountersStat, error) { +func IOCountersForNames(names []string) (map[string]IOCountersStat, error) { if C.StartIOCounterFetch() == 0 { return nil, errors.New("Unable to fetch disk list") } @@ -78,6 +80,10 @@ func IOCounters() (map[string]IOCountersStat, error) { Name: strings.TrimFunc(C.GoStringN(&di.DiskName[0], C.MAX_DISK_NAME), isRuneNull), } + if len(names) > 0 && !common.StringsHas(names, d.Name) { + continue + } + ret[d.Name] = d } diff --git a/disk/disk_darwin_nocgo.go b/disk/disk_darwin_nocgo.go index 502c3b9..40c4426 100644 --- a/disk/disk_darwin_nocgo.go +++ b/disk/disk_darwin_nocgo.go @@ -5,6 +5,6 @@ package disk import "github.com/shirou/gopsutil/internal/common" -func IOCounters() (map[string]IOCountersStat, error) { +func IOCountersForNames(names []string) (map[string]IOCountersStat, error) { return nil, common.ErrNotImplementedError }