Skip to content

Commit d4a1cc9

Browse files
authored
chore: remove refs to deprecated io/ioutil (#1092)
* chore: remove refs to deprecated io/ioutil Signed-off-by: guoguangwu <[email protected]> * fix: gofmt check Signed-off-by: guoguangwu <[email protected]> --------- Signed-off-by: guoguangwu <[email protected]>
1 parent 495411a commit d4a1cc9

File tree

11 files changed

+20
-29
lines changed

11 files changed

+20
-29
lines changed

pkg/build/gobuild.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
gb "go/build"
2424
"io"
25-
"io/ioutil"
2625
"log"
2726
"os"
2827
"os/exec"
@@ -288,7 +287,7 @@ func build(ctx context.Context, ip string, dir string, platform v1.Platform, con
288287
return "", fmt.Errorf("creating KOCACHE bin dir: %w", err)
289288
}
290289
} else {
291-
tmpDir, err = ioutil.TempDir("", "ko")
290+
tmpDir, err = os.MkdirTemp("", "ko")
292291
if err != nil {
293292
return "", err
294293
}
@@ -846,7 +845,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl
846845
}
847846
dataLayerBytes := dataLayerBuf.Bytes()
848847
dataLayer, err := tarball.LayerFromOpener(func() (io.ReadCloser, error) {
849-
return ioutil.NopCloser(bytes.NewBuffer(dataLayerBytes)), nil
848+
return io.NopCloser(bytes.NewBuffer(dataLayerBytes)), nil
850849
}, tarball.WithCompressedCaching, tarball.WithMediaType(layerMediaType))
851850
if err != nil {
852851
return nil, err
@@ -957,7 +956,7 @@ func buildLayer(appPath, file string, platform *v1.Platform, layerMediaType type
957956
}
958957
binaryLayerBytes := binaryLayerBuf.Bytes()
959958
return tarball.LayerFromOpener(func() (io.ReadCloser, error) {
960-
return ioutil.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil
959+
return io.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil
961960
}, tarball.WithCompressedCaching, tarball.WithEstargzOptions(estargz.WithPrioritizedFiles([]string{
962961
// When using estargz, prioritize downloading the binary entrypoint.
963962
appPath,

pkg/build/gobuild_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"os"
2524
"path"
2625
"path/filepath"
@@ -403,12 +402,12 @@ func fauxSBOM(context.Context, string, string, string, oci.SignedEntity, string)
403402

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

411-
file, err := ioutil.TempFile(tmpDir, "out")
410+
file, err := os.CreateTemp(tmpDir, "out")
412411
if err != nil {
413412
return "", err
414413
}
@@ -573,7 +572,7 @@ func validateImage(t *testing.T, img oci.SignedImage, baseLayers int64, creation
573572
continue
574573
}
575574
found = true
576-
body, err := ioutil.ReadAll(tr)
575+
body, err := io.ReadAll(tr)
577576
if err != nil {
578577
t.Errorf("ReadAll() = %v", err)
579578
} else if want, got := "Hello there\n", string(body); got != want {

pkg/commands/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package commands
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"log"
2222
"os"
2323
"strconv"
@@ -40,7 +40,7 @@ import (
4040
)
4141

4242
var (
43-
amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(ioutil.Discard)))
43+
amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(io.Discard)))
4444
azureKeychain authn.Keychain = authn.NewKeychainFromHelper(credhelper.NewACRCredentialsHelper())
4545
keychain = authn.NewMultiKeychain(
4646
amazonKeychain,

pkg/commands/resolver.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"os"
2524
"path"
2625
"strings"
@@ -423,9 +422,9 @@ func resolveFile(
423422
}
424423

425424
if f == "-" {
426-
b, err = ioutil.ReadAll(os.Stdin)
425+
b, err = io.ReadAll(os.Stdin)
427426
} else {
428-
b, err = ioutil.ReadFile(f)
427+
b, err = os.ReadFile(f)
429428
}
430429
if err != nil {
431430
return nil, err

pkg/commands/resolver_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"log"
2524
"net/http/httptest"
25+
"os"
2626
"path"
2727
"strings"
2828
"testing"
@@ -317,7 +317,7 @@ func TestNewPublisherCanPublish(t *testing.T) {
317317
// The registry uses a NOP logger to avoid spamming test logs.
318318
// Remember to call `defer Close()` on the returned `httptest.Server`.
319319
func registryServerWithImage(namespace string) (*httptest.Server, error) {
320-
nopLog := log.New(ioutil.Discard, "", 0)
320+
nopLog := log.New(io.Discard, "", 0)
321321
r := registry.New(registry.Logger(nopLog))
322322
s := httptest.NewServer(r)
323323
imageName := fmt.Sprintf("%s/%s", s.Listener.Addr().String(), namespace)
@@ -356,7 +356,7 @@ func mustRandom() v1.Image {
356356
func yamlToTmpFile(t *testing.T, yaml []byte) string {
357357
t.Helper()
358358

359-
tmpfile, err := ioutil.TempFile("", "doc")
359+
tmpfile, err := os.CreateTemp("", "doc")
360360
if err != nil {
361361
t.Fatalf("error creating temp file: %v", err)
362362
}

pkg/internal/testing/daemon.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package testing
1717
import (
1818
"context"
1919
"io"
20-
"io/ioutil"
2120
"strings"
2221

2322
"github.com/docker/docker/api/types"
@@ -32,7 +31,7 @@ type MockDaemon struct {
3231
func (m *MockDaemon) NegotiateAPIVersion(context.Context) {}
3332
func (m *MockDaemon) ImageLoad(context.Context, io.Reader, bool) (types.ImageLoadResponse, error) {
3433
return types.ImageLoadResponse{
35-
Body: ioutil.NopCloser(strings.NewReader("Loaded")),
34+
Body: io.NopCloser(strings.NewReader("Loaded")),
3635
}, nil
3736
}
3837

pkg/publish/kind/write_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"errors"
2020
"fmt"
2121
"io"
22-
"io/ioutil"
2322
"strings"
2423
"testing"
2524

@@ -203,7 +202,7 @@ type fakeCmd struct {
203202
func (f *fakeCmd) Run() error {
204203
if f.stdin != nil {
205204
// Consume the entire stdin to move the image publish forward.
206-
ioutil.ReadAll(f.stdin)
205+
io.ReadAll(f.stdin)
207206
}
208207
return f.err
209208
}

pkg/publish/layout_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package publish
1616

1717
import (
1818
"context"
19-
"io/ioutil"
2019
"os"
2120
"strings"
2221
"testing"
@@ -31,7 +30,7 @@ func TestLayout(t *testing.T) {
3130
}
3231
importpath := "github.com/Google/go-containerregistry/cmd/crane"
3332

34-
tmp, err := ioutil.TempDir("/tmp", "ko")
33+
tmp, err := os.MkdirTemp("/tmp", "ko")
3534
if err != nil {
3635
t.Fatal(err)
3736
}

pkg/publish/multi_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package publish_test
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"testing"
2322

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

37-
fp, err := ioutil.TempFile("", "")
36+
fp, err := os.CreateTemp("", "")
3837
if err != nil {
3938
t.Fatal(err)
4039
}
@@ -43,7 +42,7 @@ func TestMulti(t *testing.T) {
4342

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

46-
tmp, err := ioutil.TempDir("/tmp", "ko")
45+
tmp, err := os.MkdirTemp("/tmp", "ko")
4746
if err != nil {
4847
t.Fatal(err)
4948
}

pkg/publish/tarball_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package publish_test
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"strings"
2322
"testing"
@@ -35,7 +34,7 @@ func TestTarball(t *testing.T) {
3534
base := "blah"
3635
importpath := "github.com/Google/go-containerregistry/cmd/crane"
3736

38-
fp, err := ioutil.TempFile("", "")
37+
fp, err := os.CreateTemp("", "")
3938
if err != nil {
4039
t.Fatal(err)
4140
}

test/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"flag"
1919
"fmt"
20-
"io/ioutil"
2120
"log"
2221
"os"
2322
"os/signal"
@@ -63,7 +62,7 @@ func main() {
6362

6463
dp := os.Getenv("KO_DATA_PATH")
6564
file := filepath.Join(dp, *f)
66-
bytes, err := ioutil.ReadFile(file)
65+
bytes, err := os.ReadFile(file)
6766
if err != nil {
6867
log.Fatalf("Error reading %q: %v", file, err)
6968
}

0 commit comments

Comments
 (0)