From c4d92ba75495a5d0ddfa54a05c99357f867fc37e Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 21 Sep 2023 14:40:43 +0300 Subject: [PATCH] Remove usage of deprecated io/ioutil package --- docs/update.go | 3 +-- internal/chunkedfile/chunkedfile.go | 4 ++-- lib/proto/cmd/star2proto/star2proto.go | 3 +-- starlark/bench_test.go | 6 +++--- starlark/eval.go | 3 +-- starlark/profile_test.go | 4 +--- syntax/parse_test.go | 4 ++-- syntax/scan.go | 5 ++--- syntax/scan_test.go | 4 ++-- 9 files changed, 15 insertions(+), 21 deletions(-) diff --git a/docs/update.go b/docs/update.go index be404279..6f886953 100644 --- a/docs/update.go +++ b/docs/update.go @@ -14,7 +14,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -51,7 +50,7 @@ func main() { html := filepath.Join(subdir, "index.html") if _, err := os.Stat(html); os.IsNotExist(err) { data := strings.Replace(defaultHTML, "$PKG", pkg, -1) - if err := ioutil.WriteFile(html, []byte(data), 0666); err != nil { + if err := os.WriteFile(html, []byte(data), 0666); err != nil { log.Fatal(err) } log.Printf("created %s", html) diff --git a/internal/chunkedfile/chunkedfile.go b/internal/chunkedfile/chunkedfile.go index babcf1b0..0751e85a 100644 --- a/internal/chunkedfile/chunkedfile.go +++ b/internal/chunkedfile/chunkedfile.go @@ -26,7 +26,7 @@ package chunkedfile // import "go.starlark.net/internal/chunkedfile" import ( "fmt" - "io/ioutil" + "os" "regexp" "runtime" "strconv" @@ -56,7 +56,7 @@ type Reporter interface { // by a newline so that the Go source position added by (*testing.T).Errorf // appears on a separate line so as not to confused editors. func Read(filename string, report Reporter) (chunks []Chunk) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { report.Errorf("%s", err) return diff --git a/lib/proto/cmd/star2proto/star2proto.go b/lib/proto/cmd/star2proto/star2proto.go index 791f2072..dffa6039 100644 --- a/lib/proto/cmd/star2proto/star2proto.go +++ b/lib/proto/cmd/star2proto/star2proto.go @@ -13,7 +13,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "log" "os" "strings" @@ -66,7 +65,7 @@ func main() { if *descriptors != "" { var fdset descriptorpb.FileDescriptorSet for i, filename := range strings.Split(*descriptors, ",") { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { log.Fatalf("--descriptors[%d]: %s", i, err) } diff --git a/starlark/bench_test.go b/starlark/bench_test.go index 46be8900..4ff07893 100644 --- a/starlark/bench_test.go +++ b/starlark/bench_test.go @@ -7,7 +7,7 @@ package starlark_test import ( "bytes" "fmt" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -29,7 +29,7 @@ func BenchmarkStarlark(b *testing.B) { filename := filepath.Join(testdata, file) - src, err := ioutil.ReadFile(filename) + src, err := os.ReadFile(filename) if err != nil { b.Error(err) continue @@ -126,7 +126,7 @@ func BenchmarkProgram(b *testing.B) { b.Run("read", func(b *testing.B) { for i := 0; i < b.N; i++ { var err error - src, err = ioutil.ReadFile(filename) + src, err = os.ReadFile(filename) if err != nil { b.Fatal(err) } diff --git a/starlark/eval.go b/starlark/eval.go index 3ab08e47..99e83a14 100644 --- a/starlark/eval.go +++ b/starlark/eval.go @@ -7,7 +7,6 @@ package starlark import ( "fmt" "io" - "io/ioutil" "log" "math/big" "sort" @@ -416,7 +415,7 @@ func FileProgram(f *syntax.File, isPredeclared func(string) bool) (*Program, err // CompiledProgram produces a new program from the representation // of a compiled program previously saved by Program.Write. func CompiledProgram(in io.Reader) (*Program, error) { - data, err := ioutil.ReadAll(in) + data, err := io.ReadAll(in) if err != nil { return nil, err } diff --git a/starlark/profile_test.go b/starlark/profile_test.go index 515d7d4a..773a3844 100644 --- a/starlark/profile_test.go +++ b/starlark/profile_test.go @@ -7,7 +7,6 @@ package starlark_test import ( "bytes" "fmt" - "io/ioutil" "os" "os/exec" "strings" @@ -19,12 +18,11 @@ import ( // TestProfile is a simple integration test that the profiler // emits minimally plausible pprof-compatible output. func TestProfile(t *testing.T) { - prof, err := ioutil.TempFile("", "profile_test") + prof, err := os.CreateTemp(t.TempDir(), "profile_test") if err != nil { t.Fatal(err) } defer prof.Close() - defer os.Remove(prof.Name()) if err := starlark.StartProfile(prof); err != nil { t.Fatal(err) } diff --git a/syntax/parse_test.go b/syntax/parse_test.go index fedbb3e8..197e9050 100644 --- a/syntax/parse_test.go +++ b/syntax/parse_test.go @@ -9,7 +9,7 @@ import ( "bytes" "fmt" "go/build" - "io/ioutil" + "os" "path/filepath" "reflect" "strings" @@ -472,7 +472,7 @@ var dataFile = func(pkgdir, filename string) string { func BenchmarkParse(b *testing.B) { filename := dataFile("syntax", "testdata/scan.star") b.StopTimer() - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { b.Fatal(err) } diff --git a/syntax/scan.go b/syntax/scan.go index b080202a..95499772 100644 --- a/syntax/scan.go +++ b/syntax/scan.go @@ -9,7 +9,6 @@ package syntax import ( "fmt" "io" - "io/ioutil" "log" "math/big" "os" @@ -287,7 +286,7 @@ func readSource(filename string, src interface{}) ([]byte, error) { case []byte: return src, nil case io.Reader: - data, err := ioutil.ReadAll(src) + data, err := io.ReadAll(src) if err != nil { err = &os.PathError{Op: "read", Path: filename, Err: err} return nil, err @@ -296,7 +295,7 @@ func readSource(filename string, src interface{}) ([]byte, error) { case FilePortion: return src.Content, nil case nil: - return ioutil.ReadFile(filename) + return os.ReadFile(filename) default: return nil, fmt.Errorf("invalid source: %T", src) } diff --git a/syntax/scan_test.go b/syntax/scan_test.go index 599dbbcf..cfed6c93 100644 --- a/syntax/scan_test.go +++ b/syntax/scan_test.go @@ -8,7 +8,7 @@ import ( "bytes" "fmt" "go/build" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -292,7 +292,7 @@ var dataFile = func(pkgdir, filename string) string { func BenchmarkScan(b *testing.B) { filename := dataFile("syntax", "testdata/scan.star") b.StopTimer() - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { b.Fatal(err) }