From fb1c75054a14368e1adb1cf447015244cb14ea7c Mon Sep 17 00:00:00 2001 From: shirou Date: Tue, 20 Oct 2020 18:11:00 +0900 Subject: [PATCH] [disk] Partition returns all list even if argument is False. According to https://github.com/giampaolo/psutil/issues/906, all BSD system returns same information `df` and `df -a`. --- disk/disk_darwin.go | 8 ++------ disk/disk_freebsd.go | 8 ++------ disk/disk_openbsd.go | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/disk/disk_darwin.go b/disk/disk_darwin.go index d64d15c..b0fc29a 100644 --- a/disk/disk_darwin.go +++ b/disk/disk_darwin.go @@ -4,7 +4,6 @@ package disk import ( "context" - "path" "github.com/shirou/gopsutil/internal/common" "golang.org/x/sys/unix" @@ -14,6 +13,8 @@ func Partitions(all bool) ([]PartitionStat, error) { return PartitionsWithContext(context.Background(), all) } +// PartitionsWithContext returns disk partition. +// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat @@ -69,11 +70,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro Fstype: common.ByteToString(stat.Fstypename[:]), Opts: opts, } - if all == false { - if !path.IsAbs(d.Device) || !common.PathExists(d.Device) { - continue - } - } ret = append(ret, d) } diff --git a/disk/disk_freebsd.go b/disk/disk_freebsd.go index f172828..9882781 100644 --- a/disk/disk_freebsd.go +++ b/disk/disk_freebsd.go @@ -6,7 +6,6 @@ import ( "bytes" "context" "encoding/binary" - "path" "strconv" "golang.org/x/sys/unix" @@ -18,6 +17,8 @@ func Partitions(all bool) ([]PartitionStat, error) { return PartitionsWithContext(context.Background(), all) } +// PartitionsWithContext returns disk partition. +// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat @@ -89,11 +90,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro Fstype: common.ByteToString(stat.Fstypename[:]), Opts: opts, } - if all == false { - if !path.IsAbs(d.Device) || !common.PathExists(d.Device) { - continue - } - } ret = append(ret, d) } diff --git a/disk/disk_openbsd.go b/disk/disk_openbsd.go index cd9e294..741aa89 100644 --- a/disk/disk_openbsd.go +++ b/disk/disk_openbsd.go @@ -6,7 +6,6 @@ import ( "bytes" "context" "encoding/binary" - "path" "github.com/shirou/gopsutil/internal/common" "golang.org/x/sys/unix" @@ -16,6 +15,8 @@ func Partitions(all bool) ([]PartitionStat, error) { return PartitionsWithContext(context.Background(), all) } +// PartitionsWithContext returns disk partition. +// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906 func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat @@ -66,11 +67,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro Fstype: common.IntToString(stat.F_fstypename[:]), Opts: opts, } - if all == false { - if !path.IsAbs(d.Device) || !common.PathExists(d.Device) { - continue - } - } ret = append(ret, d) }