From 919f9abf3868cd375fe430e5f66b2ff54d8c69fd Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Thu, 20 Jul 2023 18:25:32 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil Signed-off-by: guoguangwu --- archive/tar/reader.go | 7 +++---- archive/tar/reader_test.go | 5 ++--- archive/tar/tar_test.go | 11 +++++------ archive/tar/writer_test.go | 3 +-- cmd/tar-split/checksize.go | 7 +++---- cmd/tar-split/disasm.go | 3 +-- cmd/tar-split/tar_benchmark_test.go | 7 +++---- concept/main.go | 3 +-- tar/asm/assemble_test.go | 5 ++--- tar/asm/disassemble_test.go | 5 ++--- tar/storage/getter_test.go | 4 ++-- tar/storage/packer_test.go | 3 +-- 12 files changed, 26 insertions(+), 37 deletions(-) diff --git a/archive/tar/reader.go b/archive/tar/reader.go index fcf3215..af006fc 100644 --- a/archive/tar/reader.go +++ b/archive/tar/reader.go @@ -7,7 +7,6 @@ package tar import ( "bytes" "io" - "io/ioutil" "strconv" "strings" "time" @@ -140,7 +139,7 @@ func (tr *Reader) next() (*Header, error) { continue // This is a meta header affecting the next header case TypeGNULongName, TypeGNULongLink: format.mayOnlyBe(FormatGNU) - realname, err := ioutil.ReadAll(tr) + realname, err := io.ReadAll(tr) if err != nil { return nil, err } @@ -334,7 +333,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) { // parsePAX parses PAX headers. // If an extended header (type 'x') is invalid, ErrHeader is returned func parsePAX(r io.Reader) (map[string]string, error) { - buf, err := ioutil.ReadAll(r) + buf, err := io.ReadAll(r) if err != nil { return nil, err } @@ -916,7 +915,7 @@ func discard(tr *Reader, n int64) error { } } - copySkipped, err = io.CopyN(ioutil.Discard, r, n-seekSkipped) + copySkipped, err = io.CopyN(io.Discard, r, n-seekSkipped) out: if err == io.EOF && seekSkipped+copySkipped < n { err = io.ErrUnexpectedEOF diff --git a/archive/tar/reader_test.go b/archive/tar/reader_test.go index f153b66..789ddc1 100644 --- a/archive/tar/reader_test.go +++ b/archive/tar/reader_test.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "os" "path" @@ -773,7 +772,7 @@ func TestReadTruncation(t *testing.T) { "testdata/pax-path-hdr.tar", "testdata/sparse-formats.tar", } { - buf, err := ioutil.ReadFile(p) + buf, err := os.ReadFile(p) if err != nil { t.Fatalf("unexpected error: %v", err) } @@ -865,7 +864,7 @@ func TestReadTruncation(t *testing.T) { } cnt++ if s2 == "manual" { - if _, err = tr.writeTo(ioutil.Discard); err != nil { + if _, err = tr.writeTo(io.Discard); err != nil { break } } diff --git a/archive/tar/tar_test.go b/archive/tar/tar_test.go index f1ce7fb..ca6aeb0 100644 --- a/archive/tar/tar_test.go +++ b/archive/tar/tar_test.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "os" "path" @@ -264,7 +263,7 @@ func TestFileInfoHeaderSymlink(t *testing.T) { case "android", "nacl", "plan9", "windows": t.Skip("symlinks not supported") } - tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink") + tmpdir, err := os.MkdirTemp("", "TestFileInfoHeaderSymlink") if err != nil { t.Fatal(err) } @@ -329,7 +328,7 @@ func TestRoundTrip(t *testing.T) { if !reflect.DeepEqual(rHdr, hdr) { t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr) } - rData, err := ioutil.ReadAll(tr) + rData, err := io.ReadAll(tr) if err != nil { t.Fatalf("Read: %v", err) } @@ -806,9 +805,9 @@ func Benchmark(b *testing.B) { b.Run(v.label, func(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { - // Writing to ioutil.Discard because we want to + // Writing to io.Discard because we want to // test purely the writer code and not bring in disk performance into this. - tw := NewWriter(ioutil.Discard) + tw := NewWriter(io.Discard) for _, file := range v.files { if err := tw.WriteHeader(file.hdr); err != nil { b.Errorf("unexpected WriteHeader error: %v", err) @@ -846,7 +845,7 @@ func Benchmark(b *testing.B) { if _, err := tr.Next(); err != nil { b.Errorf("unexpected Next error: %v", err) } - if _, err := io.Copy(ioutil.Discard, tr); err != nil { + if _, err := io.Copy(io.Discard, tr); err != nil { b.Errorf("unexpected Copy error : %v", err) } } diff --git a/archive/tar/writer_test.go b/archive/tar/writer_test.go index 30556d2..a00f02d 100644 --- a/archive/tar/writer_test.go +++ b/archive/tar/writer_test.go @@ -9,7 +9,6 @@ import ( "encoding/hex" "errors" "io" - "io/ioutil" "os" "path" "reflect" @@ -520,7 +519,7 @@ func TestWriter(t *testing.T) { } if v.file != "" { - want, err := ioutil.ReadFile(v.file) + want, err := os.ReadFile(v.file) if err != nil { t.Fatalf("ReadFile() = %v, want nil", err) } diff --git a/cmd/tar-split/checksize.go b/cmd/tar-split/checksize.go index cea8e36..0343682 100644 --- a/cmd/tar-split/checksize.go +++ b/cmd/tar-split/checksize.go @@ -5,7 +5,6 @@ import ( "compress/gzip" "fmt" "io" - "io/ioutil" "log" "os" @@ -31,7 +30,7 @@ func CommandChecksize(c *cli.Context) { } fmt.Printf("inspecting %q (size %dk)\n", fh.Name(), fi.Size()/1024) - packFh, err := ioutil.TempFile("", "packed.") + packFh, err := os.CreateTemp("", "packed.") if err != nil { log.Fatal(err) } @@ -60,7 +59,7 @@ func CommandChecksize(c *cli.Context) { log.Fatal(err) } num++ - if _, err := io.Copy(ioutil.Discard, tr); err != nil { + if _, err := io.Copy(io.Discard, tr); err != nil { log.Fatal(err) } } @@ -76,7 +75,7 @@ func CommandChecksize(c *cli.Context) { } fmt.Printf(" -- size of metadata uncompressed: %dk\n", fi.Size()/1024) - gzPackFh, err := ioutil.TempFile("", "packed.gz.") + gzPackFh, err := os.CreateTemp("", "packed.gz.") if err != nil { log.Fatal(err) } diff --git a/cmd/tar-split/disasm.go b/cmd/tar-split/disasm.go index d3df786..3c8b5b8 100644 --- a/cmd/tar-split/disasm.go +++ b/cmd/tar-split/disasm.go @@ -3,7 +3,6 @@ package main import ( "compress/gzip" "io" - "io/ioutil" "os" "github.com/sirupsen/logrus" @@ -51,7 +50,7 @@ func CommandDisasm(c *cli.Context) { } var out io.Writer if c.Bool("no-stdout") { - out = ioutil.Discard + out = io.Discard } else { out = os.Stdout } diff --git a/cmd/tar-split/tar_benchmark_test.go b/cmd/tar-split/tar_benchmark_test.go index 950eccc..8b7aaff 100644 --- a/cmd/tar-split/tar_benchmark_test.go +++ b/cmd/tar-split/tar_benchmark_test.go @@ -2,7 +2,6 @@ package main import ( "io" - "io/ioutil" "os" "testing" @@ -29,7 +28,7 @@ func BenchmarkUpstreamTar(b *testing.B) { fh.Close() b.Fatal(err) } - _, err = io.Copy(ioutil.Discard, tr) + _, err = io.Copy(io.Discard, tr) if err != nil { b.Fatal(err) } @@ -57,7 +56,7 @@ func BenchmarkOurTarNoAccounting(b *testing.B) { fh.Close() b.Fatal(err) } - _, err = io.Copy(ioutil.Discard, tr) + _, err = io.Copy(io.Discard, tr) if err != nil { b.Fatal(err) } @@ -86,7 +85,7 @@ func BenchmarkOurTarYesAccounting(b *testing.B) { fh.Close() b.Fatal(err) } - _, err = io.Copy(ioutil.Discard, tr) + _, err = io.Copy(io.Discard, tr) if err != nil { b.Fatal(err) } diff --git a/concept/main.go b/concept/main.go index 1a6aeea..0f32f62 100644 --- a/concept/main.go +++ b/concept/main.go @@ -7,7 +7,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "os" @@ -73,7 +72,7 @@ func main() { // it is allowable, and not uncommon that there is further padding on the // end of an archive, apart from the expected 1024 null bytes - remainder, err := ioutil.ReadAll(fh) + remainder, err := io.ReadAll(fh) if err != nil && err != io.EOF { log.Fatal(err, fh.Name()) } diff --git a/tar/asm/assemble_test.go b/tar/asm/assemble_test.go index afdce9d..6cb7850 100644 --- a/tar/asm/assemble_test.go +++ b/tar/asm/assemble_test.go @@ -7,7 +7,6 @@ import ( "fmt" "hash/crc64" "io" - "io/ioutil" "os" "testing" @@ -232,7 +231,7 @@ func BenchmarkAsm(b *testing.B) { b.Fatal(err) } // read it all to the bit bucket - i1, err := io.Copy(ioutil.Discard, tarStream) + i1, err := io.Copy(io.Discard, tarStream) if err != nil { b.Fatal(err) } @@ -243,7 +242,7 @@ func BenchmarkAsm(b *testing.B) { rc := NewOutputTarStream(fgp, sup) - i2, err := io.Copy(ioutil.Discard, rc) + i2, err := io.Copy(io.Discard, rc) if err != nil { b.Fatal(err) } diff --git a/tar/asm/disassemble_test.go b/tar/asm/disassemble_test.go index 4141aa0..84a3e77 100644 --- a/tar/asm/disassemble_test.go +++ b/tar/asm/disassemble_test.go @@ -4,7 +4,6 @@ import ( "archive/tar" "fmt" "io" - "io/ioutil" "os" "testing" @@ -52,14 +51,14 @@ func TestLargeJunkPadding(t *testing.T) { }() // Disassemble our junk file. - nilPacker := storage.NewJSONPacker(ioutil.Discard) + nilPacker := storage.NewJSONPacker(io.Discard) rdr, err := NewInputTarStream(pR, nilPacker, nil) if err != nil { t.Fatal(err) } // Copy the entire rdr. - _, err = io.Copy(ioutil.Discard, rdr) + _, err = io.Copy(io.Discard, rdr) if err != nil { t.Fatal(err) } diff --git a/tar/storage/getter_test.go b/tar/storage/getter_test.go index c06cff0..f03c1cd 100644 --- a/tar/storage/getter_test.go +++ b/tar/storage/getter_test.go @@ -3,7 +3,7 @@ package storage import ( "bytes" "fmt" - "io/ioutil" + "io" "strings" "testing" ) @@ -31,7 +31,7 @@ func TestGetter(t *testing.T) { if err != nil { t.Error(err) } - buf, err := ioutil.ReadAll(r) + buf, err := io.ReadAll(r) if err != nil { t.Error(err) } diff --git a/tar/storage/packer_test.go b/tar/storage/packer_test.go index 082c0d8..ec837f4 100644 --- a/tar/storage/packer_test.go +++ b/tar/storage/packer_test.go @@ -4,7 +4,6 @@ import ( "bytes" "compress/gzip" "io" - "io/ioutil" "os" "testing" ) @@ -186,7 +185,7 @@ func BenchmarkGetPut(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { func() { - fh, err := ioutil.TempFile("", "tar-split.") + fh, err := os.CreateTemp("", "tar-split.") if err != nil { b.Fatal(err) }