Skip to content

Commit 8e7b658

Browse files
authored
Merge pull request docker#9595 from abhinavnair/replace-ioutil
Replace deprecated ioutil pkg with os & io
2 parents 391d2e0 + a783cc4 commit 8e7b658

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ linters:
77
disable-all: true
88
enable:
99
- deadcode
10+
- depguard
1011
- errcheck
1112
- gocyclo
1213
- gofmt
@@ -26,6 +27,13 @@ linters:
2627
- unused
2728
- varcheck
2829
linters-settings:
30+
depguard:
31+
list-type: blacklist
32+
include-go-root: true
33+
packages:
34+
# The io/ioutil package has been deprecated.
35+
# https://go.dev/doc/go1.16#ioutil
36+
- io/ioutil
2937
gocyclo:
3038
min-complexity: 16
3139
lll:

pkg/compose/build_classic.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"io"
24-
"io/ioutil"
2524
"os"
2625
"path/filepath"
2726
"runtime"
@@ -215,7 +214,7 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
215214
if imageID == "" {
216215
return "", errors.Errorf("Server did not provide an image ID. Cannot write %s", options.ImageIDFile)
217216
}
218-
if err := ioutil.WriteFile(options.ImageIDFile, []byte(imageID), 0666); err != nil {
217+
if err := os.WriteFile(options.ImageIDFile, []byte(imageID), 0666); err != nil {
219218
return "", err
220219
}
221220
}

pkg/compose/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"os"
2525
"path"
2626
"path/filepath"
2727
"strconv"
@@ -414,7 +414,7 @@ func parseSecurityOpts(p *types.Project, securityOpts []string) ([]string, error
414414
}
415415
}
416416
if con[0] == "seccomp" && con[1] != "unconfined" {
417-
f, err := ioutil.ReadFile(p.RelativePath(con[1]))
417+
f, err := os.ReadFile(p.RelativePath(con[1]))
418418
if err != nil {
419419
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
420420
}

pkg/e2e/compose_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package e2e
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"net/http"
2322
"os"
2423
"path/filepath"
@@ -133,7 +132,7 @@ func TestComposePull(t *testing.T) {
133132
func TestDownComposefileInParentFolder(t *testing.T) {
134133
c := NewParallelCLI(t)
135134

136-
tmpFolder, err := ioutil.TempDir("fixtures/simple-composefile", "test-tmp")
135+
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
137136
assert.NilError(t, err)
138137
defer os.Remove(tmpFolder) // nolint: errcheck
139138
projectName := filepath.Base(tmpFolder)

pkg/e2e/framework.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package e2e
1919
import (
2020
"fmt"
2121
"io"
22-
"io/ioutil"
2322
"net/http"
2423
"os"
2524
"path"
@@ -115,7 +114,7 @@ func initializePlugins(t testing.TB, configDir string) {
115114

116115
t.Cleanup(func() {
117116
if t.Failed() {
118-
if conf, err := ioutil.ReadFile(filepath.Join(configDir, "config.json")); err == nil {
117+
if conf, err := os.ReadFile(filepath.Join(configDir, "config.json")); err == nil {
119118
t.Logf("Config: %s\n", string(conf))
120119
}
121120
t.Log("Contents of config dir:")
@@ -389,7 +388,7 @@ func HTTPGetWithRetry(
389388
}
390389
poll.WaitOn(t, checkUp, poll.WithDelay(retryDelay), poll.WithTimeout(timeout))
391390
if r != nil {
392-
b, err := ioutil.ReadAll(r.Body)
391+
b, err := io.ReadAll(r.Body)
393392
assert.NilError(t, err)
394393
return string(b)
395394
}

pkg/e2e/scan_message_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package e2e
1818

1919
import (
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"strings"
@@ -74,7 +73,7 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
7473
t.Run("do not display if scan already invoked", func(t *testing.T) {
7574
_ = os.MkdirAll(filepath.Join(c.ConfigDir, "scan"), 0755)
7675
scanConfigFile := filepath.Join(c.ConfigDir, "scan", "config.json")
77-
err := ioutil.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0644)
76+
err := os.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0644)
7877
assert.NilError(t, err)
7978

8079
res := c.RunDockerCmd(t, "build", "-t", "test-image-scan-msg", "fixtures/simple-build-test/nginx-build")

pkg/utils/scan_suggest.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package utils
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524

@@ -57,7 +56,7 @@ func scanAlreadyInvoked() bool {
5756
type scanOptin struct {
5857
Optin bool `json:"optin"`
5958
}
60-
data, err := ioutil.ReadFile(filename)
59+
data, err := os.ReadFile(filename)
6160
if err != nil {
6261
return true
6362
}

0 commit comments

Comments
 (0)