Replace deprecated ioutil pkg with os & io

As of Go 1.16, the same functionality is now provided by package io or
package os, and those implementations should be preferred in new code.

So replacing all usage of ioutil pkg with io & os.

Signed-off-by: Abhinav Nair <11939846+abhinavnair@users.noreply.github.com>
This commit is contained in:
Abhinav Nair 2022-06-25 14:02:21 +08:00
parent 2cd9c0df5a
commit 11f2f2dbc4
No known key found for this signature in database
GPG Key ID: 1724728BA191F70C
6 changed files with 8 additions and 13 deletions

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -215,7 +214,7 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
if imageID == "" {
return "", errors.Errorf("Server did not provide an image ID. Cannot write %s", options.ImageIDFile)
}
if err := ioutil.WriteFile(options.ImageIDFile, []byte(imageID), 0666); err != nil {
if err := os.WriteFile(options.ImageIDFile, []byte(imageID), 0666); err != nil {
return "", err
}
}

View File

@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strconv"
@ -414,7 +414,7 @@ func parseSecurityOpts(p *types.Project, securityOpts []string) ([]string, error
}
}
if con[0] == "seccomp" && con[1] != "unconfined" {
f, err := ioutil.ReadFile(p.RelativePath(con[1]))
f, err := os.ReadFile(p.RelativePath(con[1]))
if err != nil {
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
}

View File

@ -18,7 +18,6 @@ package e2e
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -133,7 +132,7 @@ func TestComposePull(t *testing.T) {
func TestDownComposefileInParentFolder(t *testing.T) {
c := NewParallelCLI(t)
tmpFolder, err := ioutil.TempDir("fixtures/simple-composefile", "test-tmp")
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
assert.NilError(t, err)
defer os.Remove(tmpFolder) // nolint: errcheck
projectName := filepath.Base(tmpFolder)

View File

@ -19,7 +19,6 @@ package e2e
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
@ -115,7 +114,7 @@ func initializePlugins(t testing.TB, configDir string) {
t.Cleanup(func() {
if t.Failed() {
if conf, err := ioutil.ReadFile(filepath.Join(configDir, "config.json")); err == nil {
if conf, err := os.ReadFile(filepath.Join(configDir, "config.json")); err == nil {
t.Logf("Config: %s\n", string(conf))
}
t.Log("Contents of config dir:")
@ -389,7 +388,7 @@ func HTTPGetWithRetry(
}
poll.WaitOn(t, checkUp, poll.WithDelay(retryDelay), poll.WithTimeout(timeout))
if r != nil {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
assert.NilError(t, err)
return string(b)
}

View File

@ -17,7 +17,6 @@
package e2e
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -74,7 +73,7 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
t.Run("do not display if scan already invoked", func(t *testing.T) {
_ = os.MkdirAll(filepath.Join(c.ConfigDir, "scan"), 0755)
scanConfigFile := filepath.Join(c.ConfigDir, "scan", "config.json")
err := ioutil.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0644)
err := os.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0644)
assert.NilError(t, err)
res := c.RunDockerCmd(t, "build", "-t", "test-image-scan-msg", "fixtures/simple-build-test/nginx-build")

View File

@ -19,7 +19,6 @@ package utils
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -57,7 +56,7 @@ func scanAlreadyInvoked() bool {
type scanOptin struct {
Optin bool `json:"optin"`
}
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return true
}