Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usages of the deprecated io/ioutil pkg #220

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/220.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Replace usages of the deprecated io/ioutil package.
```
4 changes: 2 additions & 2 deletions providers/aix/os_aix_ppc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package aix

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"

Expand All @@ -40,7 +40,7 @@ func getOSInfo() (*types.OSInfo, error) {
}

// Retrieve build version from "/proc/version".
procVersion, err := ioutil.ReadFile("/proc/version")
procVersion, err := os.ReadFile("/proc/version")
if err != nil {
return nil, fmt.Errorf("failed to get OS info: cannot open /proc/version: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion providers/aix/process_aix_ppc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
func (aixSystem) Processes() ([]types.Process, error) {
// Retrieve processes using /proc instead of calling
// getprocs which will also retrieve kernel threads.
files, err := ioutil.ReadDir("/proc")
files, err := os.ReadDir("/proc")
if err != nil {
return nil, fmt.Errorf("error while reading /proc: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions providers/darwin/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package darwin

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"

Expand All @@ -37,7 +37,7 @@ const (
)

func OperatingSystem() (*types.OSInfo, error) {
data, err := ioutil.ReadFile(systemVersionPlist)
data, err := os.ReadFile(systemVersionPlist)
if err != nil {
return nil, fmt.Errorf("failed to read plist file: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions providers/linux/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
)

const procOneCgroup = "/proc/1/cgroup"

// IsContainerized returns true if this process is containerized.
func IsContainerized() (bool, error) {
data, err := ioutil.ReadFile(procOneCgroup)
data, err := os.ReadFile(procOneCgroup)
if err != nil {
if os.IsNotExist(err) {
return false, nil
Expand Down
9 changes: 4 additions & 5 deletions providers/linux/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -65,7 +64,7 @@ func (h *host) Info() types.HostInfo {
}

func (h *host) Memory() (*types.HostMemoryInfo, error) {
content, err := ioutil.ReadFile(h.procFS.path("meminfo"))
content, err := os.ReadFile(h.procFS.path("meminfo"))
if err != nil {
return nil, err
}
Expand All @@ -83,7 +82,7 @@ func (h *host) FQDN() (string, error) {

// VMStat reports data from /proc/vmstat on linux.
func (h *host) VMStat() (*types.VMStatInfo, error) {
content, err := ioutil.ReadFile(h.procFS.path("vmstat"))
content, err := os.ReadFile(h.procFS.path("vmstat"))
if err != nil {
return nil, err
}
Expand All @@ -107,7 +106,7 @@ func (h *host) LoadAverage() (*types.LoadAverageInfo, error) {

// NetworkCounters reports data from /proc/net on linux
func (h *host) NetworkCounters() (*types.NetworkCountersInfo, error) {
snmpRaw, err := ioutil.ReadFile(h.procFS.path("net/snmp"))
snmpRaw, err := os.ReadFile(h.procFS.path("net/snmp"))
if err != nil {
return nil, err
}
Expand All @@ -116,7 +115,7 @@ func (h *host) NetworkCounters() (*types.NetworkCountersInfo, error) {
return nil, err
}

netstatRaw, err := ioutil.ReadFile(h.procFS.path("net/netstat"))
netstatRaw, err := os.ReadFile(h.procFS.path("net/netstat"))
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/linux/machineid.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package linux
import (
"bytes"
"fmt"
"io/ioutil"
"os"

"github.com/elastic/go-sysinfo/types"
Expand All @@ -35,7 +34,7 @@ func MachineID() (string, error) {
var err error

for _, file := range machineIDFiles {
contents, err = ioutil.ReadFile(file)
contents, err = os.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
// Try next location
Expand Down
13 changes: 6 additions & 7 deletions providers/linux/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package linux

import (
"bytes"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -180,7 +179,7 @@ func (p *process) OpenHandleCount() (int, error) {

func (p *process) Environment() (map[string]string, error) {
// TODO: add Environment to procfs
content, err := ioutil.ReadFile(p.path("environ"))
content, err := os.ReadFile(p.path("environ"))
if err != nil {
return nil, err
}
Expand All @@ -205,7 +204,7 @@ func (p *process) Environment() (map[string]string, error) {
}

func (p *process) Seccomp() (*types.SeccompInfo, error) {
content, err := ioutil.ReadFile(p.path("status"))
content, err := os.ReadFile(p.path("status"))
if err != nil {
return nil, err
}
Expand All @@ -214,7 +213,7 @@ func (p *process) Seccomp() (*types.SeccompInfo, error) {
}

func (p *process) Capabilities() (*types.CapabilityInfo, error) {
content, err := ioutil.ReadFile(p.path("status"))
content, err := os.ReadFile(p.path("status"))
if err != nil {
return nil, err
}
Expand All @@ -223,7 +222,7 @@ func (p *process) Capabilities() (*types.CapabilityInfo, error) {
}

func (p *process) User() (types.UserInfo, error) {
content, err := ioutil.ReadFile(p.path("status"))
content, err := os.ReadFile(p.path("status"))
if err != nil {
return types.UserInfo{}, err
}
Expand Down Expand Up @@ -255,7 +254,7 @@ func (p *process) User() (types.UserInfo, error) {

// NetworkStats reports network stats for an individual PID.
func (p *process) NetworkCounters() (*types.NetworkCountersInfo, error) {
snmpRaw, err := ioutil.ReadFile(p.path("net/snmp"))
snmpRaw, err := os.ReadFile(p.path("net/snmp"))
if err != nil {
return nil, err
}
Expand All @@ -264,7 +263,7 @@ func (p *process) NetworkCounters() (*types.NetworkCountersInfo, error) {
return nil, err
}

netstatRaw, err := ioutil.ReadFile(p.path("net/netstat"))
netstatRaw, err := os.ReadFile(p.path("net/netstat"))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/linux/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
)

Expand Down Expand Up @@ -51,7 +51,7 @@ func parseKeyValue(content []byte, separator byte, callback func(key, value []by
}

func findValue(filename, separator, key string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down