1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

[net][linux] Fix #1198 "f.ReadDir undefined" on Go 1.15 by redefining a custom readDir according to go version

Using os.File.Readdir pre Go 1.16 and os.File.ReadDir post Go 1.16
This commit is contained in:
Lomanic 2022-01-01 17:10:26 +01:00
parent 2f8da0a394
commit d826e14e27
3 changed files with 25 additions and 1 deletions

View File

@ -549,7 +549,7 @@ func getProcInodes(root string, pid int32, max int) (map[string][]inodeMap, erro
return ret, err
}
defer f.Close()
dirEntries, err := f.ReadDir(max)
dirEntries, err := readDir(f, max)
if err != nil {
return ret, err
}

12
net/net_linux_111.go Normal file
View File

@ -0,0 +1,12 @@
//go:build !go1.16
// +build !go1.16
package net
import (
"os"
)
func readDir(f *os.File, max int) ([]os.FileInfo, error) {
return f.Readdir(max)
}

12
net/net_linux_116.go Normal file
View File

@ -0,0 +1,12 @@
//go:build go1.16
// +build go1.16
package net
import (
"os"
)
func readDir(f *os.File, max int) ([]os.DirEntry, error) {
return f.ReadDir(max)
}