From d826e14e2792247ad0b4c34c56f0c07d0870fdaa Mon Sep 17 00:00:00 2001 From: Lomanic <5020919+Lomanic@users.noreply.github.com> Date: Sat, 1 Jan 2022 17:10:26 +0100 Subject: [PATCH] [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 --- net/net_linux.go | 2 +- net/net_linux_111.go | 12 ++++++++++++ net/net_linux_116.go | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 net/net_linux_111.go create mode 100644 net/net_linux_116.go diff --git a/net/net_linux.go b/net/net_linux.go index d856b9e..d323781 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -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 } diff --git a/net/net_linux_111.go b/net/net_linux_111.go new file mode 100644 index 0000000..bd5c958 --- /dev/null +++ b/net/net_linux_111.go @@ -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) +} diff --git a/net/net_linux_116.go b/net/net_linux_116.go new file mode 100644 index 0000000..a45072e --- /dev/null +++ b/net/net_linux_116.go @@ -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) +}