Skip to content

Commit 96ff4d1

Browse files
authored
Merge branch 'main' into FreeBSD
2 parents d3ab680 + df3b073 commit 96ff4d1

File tree

10 files changed

+23
-24
lines changed

10 files changed

+23
-24
lines changed

.changelog/220.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
Replace usages of the deprecated io/ioutil package.
3+
```

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
run: echo "CGO_ENABLED=0" >> $GITHUB_ENV
7979

8080
- name: golangci-lint
81-
uses: golangci/golangci-lint-action@v4
81+
uses: golangci/golangci-lint-action@v6
8282
if: github.event_name == 'pull_request'
8383
with:
8484
version: latest

providers/aix/os_aix_ppc64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package aix
2121

2222
import (
2323
"fmt"
24-
"io/ioutil"
24+
"os"
2525
"strconv"
2626
"strings"
2727

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

4242
// Retrieve build version from "/proc/version".
43-
procVersion, err := ioutil.ReadFile("/proc/version")
43+
procVersion, err := os.ReadFile("/proc/version")
4444
if err != nil {
4545
return nil, fmt.Errorf("failed to get OS info: cannot open /proc/version: %w", err)
4646
}

providers/aix/process_aix_ppc64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import (
5151
func (aixSystem) Processes() ([]types.Process, error) {
5252
// Retrieve processes using /proc instead of calling
5353
// getprocs which will also retrieve kernel threads.
54-
files, err := ioutil.ReadDir("/proc")
54+
files, err := os.ReadDir("/proc")
5555
if err != nil {
5656
return nil, fmt.Errorf("error while reading /proc: %w", err)
5757
}

providers/darwin/os.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package darwin
1919

2020
import (
2121
"fmt"
22-
"io/ioutil"
22+
"os"
2323
"strconv"
2424
"strings"
2525

@@ -37,7 +37,7 @@ const (
3737
)
3838

3939
func OperatingSystem() (*types.OSInfo, error) {
40-
data, err := ioutil.ReadFile(systemVersionPlist)
40+
data, err := os.ReadFile(systemVersionPlist)
4141
if err != nil {
4242
return nil, fmt.Errorf("failed to read plist file: %w", err)
4343
}

providers/linux/container.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ import (
2121
"bufio"
2222
"bytes"
2323
"fmt"
24-
"io/ioutil"
2524
"os"
2625
)
2726

2827
const procOneCgroup = "/proc/1/cgroup"
2928

3029
// IsContainerized returns true if this process is containerized.
3130
func IsContainerized() (bool, error) {
32-
data, err := ioutil.ReadFile(procOneCgroup)
31+
data, err := os.ReadFile(procOneCgroup)
3332
if err != nil {
3433
if os.IsNotExist(err) {
3534
return false, nil

providers/linux/host_linux.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24-
"io/ioutil"
2524
"os"
2625
"path/filepath"
2726
"strings"
@@ -65,7 +64,7 @@ func (h *host) Info() types.HostInfo {
6564
}
6665

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

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

108107
// NetworkCounters reports data from /proc/net on linux
109108
func (h *host) NetworkCounters() (*types.NetworkCountersInfo, error) {
110-
snmpRaw, err := ioutil.ReadFile(h.procFS.path("net/snmp"))
109+
snmpRaw, err := os.ReadFile(h.procFS.path("net/snmp"))
111110
if err != nil {
112111
return nil, err
113112
}
@@ -116,7 +115,7 @@ func (h *host) NetworkCounters() (*types.NetworkCountersInfo, error) {
116115
return nil, err
117116
}
118117

119-
netstatRaw, err := ioutil.ReadFile(h.procFS.path("net/netstat"))
118+
netstatRaw, err := os.ReadFile(h.procFS.path("net/netstat"))
120119
if err != nil {
121120
return nil, err
122121
}

providers/linux/machineid.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package linux
2020
import (
2121
"bytes"
2222
"fmt"
23-
"io/ioutil"
2423
"os"
2524

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

3736
for _, file := range machineIDFiles {
38-
contents, err = ioutil.ReadFile(file)
37+
contents, err = os.ReadFile(file)
3938
if err != nil {
4039
if os.IsNotExist(err) {
4140
// Try next location

providers/linux/process_linux.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package linux
1919

2020
import (
2121
"bytes"
22-
"io/ioutil"
2322
"os"
2423
"strconv"
2524
"strings"
@@ -180,7 +179,7 @@ func (p *process) OpenHandleCount() (int, error) {
180179

181180
func (p *process) Environment() (map[string]string, error) {
182181
// TODO: add Environment to procfs
183-
content, err := ioutil.ReadFile(p.path("environ"))
182+
content, err := os.ReadFile(p.path("environ"))
184183
if err != nil {
185184
return nil, err
186185
}
@@ -205,7 +204,7 @@ func (p *process) Environment() (map[string]string, error) {
205204
}
206205

207206
func (p *process) Seccomp() (*types.SeccompInfo, error) {
208-
content, err := ioutil.ReadFile(p.path("status"))
207+
content, err := os.ReadFile(p.path("status"))
209208
if err != nil {
210209
return nil, err
211210
}
@@ -214,7 +213,7 @@ func (p *process) Seccomp() (*types.SeccompInfo, error) {
214213
}
215214

216215
func (p *process) Capabilities() (*types.CapabilityInfo, error) {
217-
content, err := ioutil.ReadFile(p.path("status"))
216+
content, err := os.ReadFile(p.path("status"))
218217
if err != nil {
219218
return nil, err
220219
}
@@ -223,7 +222,7 @@ func (p *process) Capabilities() (*types.CapabilityInfo, error) {
223222
}
224223

225224
func (p *process) User() (types.UserInfo, error) {
226-
content, err := ioutil.ReadFile(p.path("status"))
225+
content, err := os.ReadFile(p.path("status"))
227226
if err != nil {
228227
return types.UserInfo{}, err
229228
}
@@ -255,7 +254,7 @@ func (p *process) User() (types.UserInfo, error) {
255254

256255
// NetworkStats reports network stats for an individual PID.
257256
func (p *process) NetworkCounters() (*types.NetworkCountersInfo, error) {
258-
snmpRaw, err := ioutil.ReadFile(p.path("net/snmp"))
257+
snmpRaw, err := os.ReadFile(p.path("net/snmp"))
259258
if err != nil {
260259
return nil, err
261260
}
@@ -264,7 +263,7 @@ func (p *process) NetworkCounters() (*types.NetworkCountersInfo, error) {
264263
return nil, err
265264
}
266265

267-
netstatRaw, err := ioutil.ReadFile(p.path("net/netstat"))
266+
netstatRaw, err := os.ReadFile(p.path("net/netstat"))
268267
if err != nil {
269268
return nil, err
270269
}

providers/linux/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"bytes"
2323
"errors"
2424
"fmt"
25-
"io/ioutil"
25+
"os"
2626
"strconv"
2727
)
2828

@@ -51,7 +51,7 @@ func parseKeyValue(content []byte, separator byte, callback func(key, value []by
5151
}
5252

5353
func findValue(filename, separator, key string) (string, error) {
54-
content, err := ioutil.ReadFile(filename)
54+
content, err := os.ReadFile(filename)
5555
if err != nil {
5656
return "", err
5757
}

0 commit comments

Comments
 (0)