Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
  • Loading branch information
testwill committed Jul 7, 2023
1 parent 1586ee4 commit 7afc87a
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 29 deletions.
7 changes: 3 additions & 4 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
gb "go/build"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -288,7 +287,7 @@ func build(ctx context.Context, ip string, dir string, platform v1.Platform, con
return "", fmt.Errorf("creating KOCACHE bin dir: %w", err)
}
} else {
tmpDir, err = ioutil.TempDir("", "ko")
tmpDir, err = os.MkdirTemp("", "ko")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -846,7 +845,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
}
dataLayerBytes := dataLayerBuf.Bytes()
dataLayer, err := tarball.LayerFromOpener(func() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewBuffer(dataLayerBytes)), nil
return io.NopCloser(bytes.NewBuffer(dataLayerBytes)), nil
}, tarball.WithCompressedCaching, tarball.WithMediaType(layerMediaType))
if err != nil {
return nil, err
Expand Down Expand Up @@ -957,7 +956,7 @@ func buildLayer(appPath, file string, platform *v1.Platform, layerMediaType type
}
binaryLayerBytes := binaryLayerBuf.Bytes()
return tarball.LayerFromOpener(func() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil
return io.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil
}, tarball.WithCompressedCaching, tarball.WithEstargzOptions(estargz.WithPrioritizedFiles([]string{
// When using estargz, prioritize downloading the binary entrypoint.
appPath,
Expand Down
7 changes: 3 additions & 4 deletions pkg/build/gobuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -403,12 +402,12 @@ func fauxSBOM(context.Context, string, string, string, oci.SignedEntity, string)

// A helper method we use to substitute for the default "build" method.
func writeTempFile(_ context.Context, s string, _ string, _ v1.Platform, _ Config) (string, error) {
tmpDir, err := ioutil.TempDir("", "ko")
tmpDir, err := os.MkdirTemp("", "ko")
if err != nil {
return "", err
}

file, err := ioutil.TempFile(tmpDir, "out")
file, err := os.CreateTemp(tmpDir, "out")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -573,7 +572,7 @@ func validateImage(t *testing.T, img oci.SignedImage, baseLayers int64, creation
continue
}
found = true
body, err := ioutil.ReadAll(tr)
body, err := io.ReadAll(tr)
if err != nil {
t.Errorf("ReadAll() = %v", err)
} else if want, got := "Hello there\n", string(body); got != want {
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package commands
import (
"context"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strconv"
Expand All @@ -41,7 +41,7 @@ import (
)

var (
amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(ioutil.Discard)))
amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(io.Discard)))
azureKeychain authn.Keychain = authn.NewKeychainFromHelper(credhelper.NewACRCredentialsHelper())
keychain = authn.NewMultiKeychain(
amazonKeychain,
Expand Down
5 changes: 2 additions & 3 deletions pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -423,9 +422,9 @@ func resolveFile(
}

if f == "-" {
b, err = ioutil.ReadAll(os.Stdin)
b, err = io.ReadAll(os.Stdin)
} else {
b, err = ioutil.ReadFile(f)
b, err = os.ReadFile(f)
}
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"log"
"net/http/httptest"
"path"
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestNewPublisherCanPublish(t *testing.T) {
// The registry uses a NOP logger to avoid spamming test logs.
// Remember to call `defer Close()` on the returned `httptest.Server`.
func registryServerWithImage(namespace string) (*httptest.Server, error) {
nopLog := log.New(ioutil.Discard, "", 0)
nopLog := log.New(io.Discard, "", 0)
r := registry.New(registry.Logger(nopLog))
s := httptest.NewServer(r)
imageName := fmt.Sprintf("%s/%s", s.Listener.Addr().String(), namespace)
Expand Down Expand Up @@ -356,7 +356,7 @@ func mustRandom() v1.Image {
func yamlToTmpFile(t *testing.T, yaml []byte) string {
t.Helper()

tmpfile, err := ioutil.TempFile("", "doc")
tmpfile, err := os.CreateTemp("", "doc")
if err != nil {
t.Fatalf("error creating temp file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/internal/testing/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package testing
import (
"context"
"io"
"io/ioutil"
"strings"

"github.com/docker/docker/api/types"
Expand All @@ -32,7 +31,7 @@ type MockDaemon struct {
func (m *MockDaemon) NegotiateAPIVersion(context.Context) {}
func (m *MockDaemon) ImageLoad(context.Context, io.Reader, bool) (types.ImageLoadResponse, error) {
return types.ImageLoadResponse{
Body: ioutil.NopCloser(strings.NewReader("Loaded")),
Body: io.NopCloser(strings.NewReader("Loaded")),
}, nil
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/publish/kind/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strings"
"testing"

Expand Down Expand Up @@ -203,7 +202,7 @@ type fakeCmd struct {
func (f *fakeCmd) Run() error {
if f.stdin != nil {
// Consume the entire stdin to move the image publish forward.
ioutil.ReadAll(f.stdin)
io.ReadAll(f.stdin)
}
return f.err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/publish/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package publish

import (
"context"
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -31,7 +30,7 @@ func TestLayout(t *testing.T) {
}
importpath := "github.com/Google/go-containerregistry/cmd/crane"

tmp, err := ioutil.TempDir("/tmp", "ko")
tmp, err := os.MkdirTemp("/tmp", "ko")
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/publish/multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package publish_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"

Expand All @@ -34,7 +33,7 @@ func TestMulti(t *testing.T) {
repoName := fmt.Sprintf("%s/%s", "example.com", base)
importpath := "github.com/Google/go-containerregistry/cmd/crane"

fp, err := ioutil.TempFile("", "")
fp, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -43,7 +42,7 @@ func TestMulti(t *testing.T) {

tp := publish.NewTarball(fp.Name(), repoName, md5Hash, []string{})

tmp, err := ioutil.TempDir("/tmp", "ko")
tmp, err := os.MkdirTemp("/tmp", "ko")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/publish/tarball_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package publish_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -35,7 +34,7 @@ func TestTarball(t *testing.T) {
base := "blah"
importpath := "github.com/Google/go-containerregistry/cmd/crane"

fp, err := ioutil.TempFile("", "")
fp, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -63,7 +62,7 @@ func main() {

dp := os.Getenv("KO_DATA_PATH")
file := filepath.Join(dp, *f)
bytes, err := ioutil.ReadFile(file)
bytes, err := os.ReadFile(file)
if err != nil {
log.Fatalf("Error reading %q: %v", file, err)
}
Expand Down

0 comments on commit 7afc87a

Please sign in to comment.