Merge pull request #1392 from brianryner8/getfsstat-count
Truncate the Getfsstat result to the count of items that were returned
This commit is contained in:
commit
39f3b34192
|
@ -20,9 +20,15 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||
return ret, err
|
||||
}
|
||||
fs := make([]unix.Statfs_t, count)
|
||||
if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil {
|
||||
count, err = unix.Getfsstat(fs, unix.MNT_WAIT)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
// On 10.14, and possibly other OS versions, the actual count may
|
||||
// be less than from the first call. Truncate to the returned count
|
||||
// to prevent accessing uninitialized entries.
|
||||
// https://github.com/shirou/gopsutil/issues/1390
|
||||
fs = fs[:count]
|
||||
for _, stat := range fs {
|
||||
opts := []string{"rw"}
|
||||
if stat.Flags&unix.MNT_RDONLY != 0 {
|
||||
|
|
Loading…
Reference in New Issue