From 981a3fdd5a755a1521337010bec47874753508cb Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Thu, 10 Nov 2022 00:07:32 +0000 Subject: [PATCH] Remove references to package io/ioutil Package io/ioutil has been marked deprecated in Go 1.16. Signed-off-by: Austin Vazquez --- .golangci.yml | 10 ++++++++++ cmd/ctd-decoder/enc_helpers.go | 3 +-- cmd/ctd-decoder/main_unix.go | 4 ++-- cmd/ctd-decoder/main_windows.go | 4 ++-- cmd/ctr/app/main.go | 4 ++-- images/encryption/parsehelpers/parsehelpers.go | 11 +++++------ 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 13ec860f..a1b4c9ec 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,6 @@ linters: enable: + - depguard - structcheck - varcheck - staticcheck @@ -18,3 +19,12 @@ run: - cmd/ctr/commands/images - cmd\\ctr\\commands\\run - cmd\\ctr\\commands\\images + +linters-settings: + depguard: + list-type: denylist + include-go-root: true + packages: + # use "io" or "os" instead + # https://go.dev/doc/go1.16#ioutil + - io/ioutil diff --git a/cmd/ctd-decoder/enc_helpers.go b/cmd/ctd-decoder/enc_helpers.go index cd36779f..6f2514d7 100644 --- a/cmd/ctd-decoder/enc_helpers.go +++ b/cmd/ctd-decoder/enc_helpers.go @@ -19,7 +19,6 @@ package main import ( b64 "encoding/base64" "errors" - "io/ioutil" "os" "path/filepath" "strings" @@ -49,7 +48,7 @@ func getDecryptionKeys(keysPath string) (encconfig.CryptoConfig, error) { return errors.New("Symbolic links not supported in decryption keys paths") } - privateKey, err := ioutil.ReadFile(path) + privateKey, err := os.ReadFile(path) if err != nil { return err } diff --git a/cmd/ctd-decoder/main_unix.go b/cmd/ctd-decoder/main_unix.go index 20d81025..41dce275 100644 --- a/cmd/ctd-decoder/main_unix.go +++ b/cmd/ctd-decoder/main_unix.go @@ -20,7 +20,7 @@ package main import ( - "io/ioutil" + "io" "os" ) @@ -29,5 +29,5 @@ const payloadFD = 3 func readPayload() ([]byte, error) { f := os.NewFile(payloadFD, "configFd") defer f.Close() - return ioutil.ReadAll(f) + return io.ReadAll(f) } diff --git a/cmd/ctd-decoder/main_windows.go b/cmd/ctd-decoder/main_windows.go index 83deabf3..53405388 100644 --- a/cmd/ctd-decoder/main_windows.go +++ b/cmd/ctd-decoder/main_windows.go @@ -21,7 +21,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "os" winio "github.com/Microsoft/go-winio" @@ -35,5 +35,5 @@ func readPayload() ([]byte, error) { return nil, fmt.Errorf("could not DialPipe: %w", err) } defer conn.Close() - return ioutil.ReadAll(conn) + return io.ReadAll(conn) } diff --git a/cmd/ctr/app/main.go b/cmd/ctr/app/main.go index 91d8e6cd..a030781b 100644 --- a/cmd/ctr/app/main.go +++ b/cmd/ctr/app/main.go @@ -18,7 +18,7 @@ package app import ( "fmt" - "io/ioutil" + "io" "github.com/containerd/containerd/cmd/ctr/commands/content" "github.com/containerd/containerd/cmd/ctr/commands/events" @@ -46,7 +46,7 @@ var extraCmds = []cli.Command{} func init() { // Discard grpc logs so that they don't mess with our stdio - grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) + grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard)) cli.VersionPrinter = func(c *cli.Context) { fmt.Println(c.App.Name, version.Package, c.App.Version) diff --git a/images/encryption/parsehelpers/parsehelpers.go b/images/encryption/parsehelpers/parsehelpers.go index 2025ec3e..8b54803f 100644 --- a/images/encryption/parsehelpers/parsehelpers.go +++ b/images/encryption/parsehelpers/parsehelpers.go @@ -21,7 +21,6 @@ package parsehelpers import ( "errors" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -69,7 +68,7 @@ func processRecipientKeys(recipients []string) ([][]byte, [][]byte, [][]byte, [] gpgRecipients = append(gpgRecipients, []byte(value)) case "jwe": - tmp, err := ioutil.ReadFile(value) + tmp, err := os.ReadFile(value) if err != nil { return nil, nil, nil, nil, nil, nil, fmt.Errorf("unable to read file: %w", err) } @@ -79,7 +78,7 @@ func processRecipientKeys(recipients []string) ([][]byte, [][]byte, [][]byte, [] pubkeys = append(pubkeys, tmp) case "pkcs7": - tmp, err := ioutil.ReadFile(value) + tmp, err := os.ReadFile(value) if err != nil { return nil, nil, nil, nil, nil, nil, fmt.Errorf("unable to read file %s: %w", value, err) } @@ -89,7 +88,7 @@ func processRecipientKeys(recipients []string) ([][]byte, [][]byte, [][]byte, [] x509s = append(x509s, tmp) case "pkcs11": - tmp, err := ioutil.ReadFile(value) + tmp, err := os.ReadFile(value) if err != nil { return nil, nil, nil, nil, nil, nil, fmt.Errorf("unable to read file %s: %w", value, err) } @@ -118,7 +117,7 @@ func processRecipientKeys(recipients []string) ([][]byte, [][]byte, [][]byte, [] // - func processPwdString(pwdString string) ([]byte, error) { if strings.HasPrefix(pwdString, "file=") { - return ioutil.ReadFile(pwdString[5:]) + return os.ReadFile(pwdString[5:]) } else if strings.HasPrefix(pwdString, "pass=") { return []byte(pwdString[5:]), nil } else if strings.HasPrefix(pwdString, "fd=") { @@ -179,7 +178,7 @@ func processPrivateKeyFiles(keyFilesAndPwds []string) ([][]byte, [][]byte, [][]b } keyfile := parts[0] - tmp, err := ioutil.ReadFile(keyfile) + tmp, err := os.ReadFile(keyfile) if err != nil { return nil, nil, nil, nil, nil, nil, err }