diff --git a/cmd/protoc-gen-go/annotation_test.go b/cmd/protoc-gen-go/annotation_test.go index 4ec1a2ba..d0fc959a 100644 --- a/cmd/protoc-gen-go/annotation_test.go +++ b/cmd/protoc-gen-go/annotation_test.go @@ -6,7 +6,7 @@ package main import ( "bytes" - "io/ioutil" + "os" "testing" "github.com/google/go-cmp/cmp" @@ -19,11 +19,11 @@ import ( ) func TestAnnotations(t *testing.T) { - sourceFile, err := ioutil.ReadFile("testdata/annotations/annotations.pb.go") + sourceFile, err := os.ReadFile("testdata/annotations/annotations.pb.go") if err != nil { t.Fatal(err) } - metaFile, err := ioutil.ReadFile("testdata/annotations/annotations.pb.go.meta") + metaFile, err := os.ReadFile("testdata/annotations/annotations.pb.go.meta") if err != nil { t.Fatal(err) } diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go index 40e5f050..af3b35e2 100644 --- a/cmd/protoc-gen-go/internal_gengo/main.go +++ b/cmd/protoc-gen-go/internal_gengo/main.go @@ -231,7 +231,7 @@ func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) { // Enum type declaration. - g.Annotate(e.GoIdent.GoName, e.Location) + g.AnnotateSymbol(e.GoIdent.GoName, protogen.Annotation{Location: e.Location}) leadingComments := appendDeprecationSuffix(e.Comments.Leading, e.Desc.ParentFile(), e.Desc.Options().(*descriptorpb.EnumOptions).GetDeprecated()) @@ -241,7 +241,7 @@ func genEnum(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) { // Enum value constants. g.P("const (") for _, value := range e.Values { - g.Annotate(value.GoIdent.GoName, value.Location) + g.AnnotateSymbol(value.GoIdent.GoName, protogen.Annotation{Location: value.Location}) leadingComments := appendDeprecationSuffix(value.Comments.Leading, value.Desc.ParentFile(), value.Desc.Options().(*descriptorpb.EnumValueOptions).GetDeprecated()) @@ -331,7 +331,7 @@ func genMessage(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) { } // Message type declaration. - g.Annotate(m.GoIdent.GoName, m.Location) + g.AnnotateSymbol(m.GoIdent.GoName, protogen.Annotation{Location: m.Location}) leadingComments := appendDeprecationSuffix(m.Comments.Leading, m.Desc.ParentFile(), m.Desc.Options().(*descriptorpb.MessageOptions).GetDeprecated()) @@ -392,7 +392,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie tags = append(tags, gotrackTags...) } - g.Annotate(m.GoIdent.GoName+"."+oneof.GoName, oneof.Location) + g.AnnotateSymbol(m.GoIdent.GoName+"."+oneof.GoName, protogen.Annotation{Location: oneof.Location}) leadingComments := oneof.Comments.Leading if leadingComments != "" { leadingComments += "\n" @@ -431,7 +431,7 @@ func genMessageField(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo, fie if field.Desc.IsWeak() { name = genid.WeakFieldPrefix_goname + name } - g.Annotate(m.GoIdent.GoName+"."+name, field.Location) + g.AnnotateSymbol(m.GoIdent.GoName+"."+name, protogen.Annotation{Location: field.Location}) leadingComments := appendDeprecationSuffix(field.Comments.Leading, field.Desc.ParentFile(), field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated()) @@ -559,7 +559,7 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI // Getter for parent oneof. if oneof := field.Oneof; oneof != nil && oneof.Fields[0] == field && !oneof.Desc.IsSynthetic() { - g.Annotate(m.GoIdent.GoName+".Get"+oneof.GoName, oneof.Location) + g.AnnotateSymbol(m.GoIdent.GoName+".Get"+oneof.GoName, protogen.Annotation{Location: oneof.Location}) g.P("func (m *", m.GoIdent.GoName, ") Get", oneof.GoName, "() ", oneofInterfaceName(oneof), " {") g.P("if m != nil {") g.P("return m.", oneof.GoName) @@ -572,7 +572,7 @@ func genMessageGetterMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageI // Getter for message field. goType, pointer := fieldGoType(g, f, field) defaultValue := fieldDefaultValue(g, f, m, field) - g.Annotate(m.GoIdent.GoName+".Get"+field.GoName, field.Location) + g.AnnotateSymbol(m.GoIdent.GoName+".Get"+field.GoName, protogen.Annotation{Location: field.Location}) leadingComments := appendDeprecationSuffix("", field.Desc.ParentFile(), field.Desc.Options().(*descriptorpb.FieldOptions).GetDeprecated()) @@ -815,8 +815,8 @@ func genMessageOneofWrapperTypes(g *protogen.GeneratedFile, f *fileInfo, m *mess g.P("}") g.P() for _, field := range oneof.Fields { - g.Annotate(field.GoIdent.GoName, field.Location) - g.Annotate(field.GoIdent.GoName+"."+field.GoName, field.Location) + g.AnnotateSymbol(field.GoIdent.GoName, protogen.Annotation{Location: field.Location}) + g.AnnotateSymbol(field.GoIdent.GoName+"."+field.GoName, protogen.Annotation{Location: field.Location}) g.P("type ", field.GoIdent, " struct {") goType, _ := fieldGoType(g, f, field) tags := structTags{ diff --git a/compiler/protogen/protogen.go b/compiler/protogen/protogen.go index c1044644..b631914d 100644 --- a/compiler/protogen/protogen.go +++ b/compiler/protogen/protogen.go @@ -19,7 +19,7 @@ import ( "go/printer" "go/token" "go/types" - "io/ioutil" + "io" "os" "path" "path/filepath" @@ -60,7 +60,7 @@ func run(opts Options, f func(*Plugin) error) error { if len(os.Args) > 1 { return fmt.Errorf("unknown argument %q (this program should be run by protoc, not directly)", os.Args[1]) } - in, err := ioutil.ReadAll(os.Stdin) + in, err := io.ReadAll(os.Stdin) if err != nil { return err } diff --git a/integration_test.go b/integration_test.go index 856340ad..46876cb8 100644 --- a/integration_test.go +++ b/integration_test.go @@ -14,7 +14,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "net/http" "os" "os/exec" @@ -229,14 +228,16 @@ func mustInitDeps(t *testing.T) { // Delete other sub-directories that are no longer relevant. defer func() { now := time.Now() - fis, _ := ioutil.ReadDir(testDir) + fis, _ := os.ReadDir(testDir) for _, fi := range fis { dir := filepath.Join(testDir, fi.Name()) if finishedDirs[dir] { os.Chtimes(dir, now, now) // best-effort continue } - if now.Sub(fi.ModTime()) < purgeTimeout { + fii, err := fi.Info() + check(err) + if now.Sub(fii.ModTime()) < purgeTimeout { continue } fmt.Printf("delete %v\n", fi.Name()) @@ -373,7 +374,7 @@ func downloadArchive(check func(error), dstPath, srcURL, skipPrefix, wantSHA256 var r io.Reader = resp.Body if wantSHA256 != "" { - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) check(err) r = bytes.NewReader(b) @@ -408,9 +409,9 @@ func downloadArchive(check func(error), dstPath, srcURL, skipPrefix, wantSHA256 mode := os.FileMode(h.Mode & 0777) switch h.Typeflag { case tar.TypeReg: - b, err := ioutil.ReadAll(tr) + b, err := io.ReadAll(tr) check(err) - check(ioutil.WriteFile(path, b, mode)) + check(os.WriteFile(path, b, mode)) case tar.TypeDir: check(os.Mkdir(path, mode)) } @@ -443,7 +444,7 @@ func mustHandleFlags(t *testing.T) { cmd.mustRun(t, "go", "build", "-trimpath", "-ldflags", "-s -w -buildid=", "-o", binPath, "./cmd/protoc-gen-go") // Archive and compress the binary. - in, err := ioutil.ReadFile(binPath) + in, err := os.ReadFile(binPath) if err != nil { t.Fatal(err) } @@ -472,7 +473,7 @@ func mustHandleFlags(t *testing.T) { tw.Close() gz.Close() } - if err := ioutil.WriteFile(binPath+suffix, out.Bytes(), 0664); err != nil { + if err := os.WriteFile(binPath+suffix, out.Bytes(), 0664); err != nil { t.Fatal(err) } } @@ -499,7 +500,7 @@ func mustHaveCopyrightHeader(t *testing.T, files []string) { var bad []string File: for _, file := range files { - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { t.Fatal(err) } diff --git a/internal/benchmarks/bench_test.go b/internal/benchmarks/bench_test.go index 2bf2b981..6112caef 100644 --- a/internal/benchmarks/bench_test.go +++ b/internal/benchmarks/bench_test.go @@ -7,7 +7,6 @@ package bench_test import ( "flag" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -175,7 +174,7 @@ func TestMain(m *testing.M) { if filepath.Ext(path) != ".pb" { return nil } - raw, err := ioutil.ReadFile(path) + raw, err := os.ReadFile(path) if err != nil { panic(err) } diff --git a/internal/cmd/generate-corpus/main.go b/internal/cmd/generate-corpus/main.go index 8f77dea9..6aa03dc8 100644 --- a/internal/cmd/generate-corpus/main.go +++ b/internal/cmd/generate-corpus/main.go @@ -12,8 +12,8 @@ package main import ( "crypto/sha1" "fmt" - "io/ioutil" "log" + "os" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" @@ -114,7 +114,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(fmt.Sprintf("internal/fuzz/wirefuzz/corpus/%x", sha1.Sum(wire)), wire, 0777); err != nil { + if err := os.WriteFile(fmt.Sprintf("internal/fuzz/wirefuzz/corpus/%x", sha1.Sum(wire)), wire, 0777); err != nil { log.Fatal(err) } @@ -122,7 +122,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(fmt.Sprintf("internal/fuzz/textfuzz/corpus/%x", sha1.Sum(text)), text, 0777); err != nil { + if err := os.WriteFile(fmt.Sprintf("internal/fuzz/textfuzz/corpus/%x", sha1.Sum(text)), text, 0777); err != nil { log.Fatal(err) } @@ -130,7 +130,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(fmt.Sprintf("internal/fuzz/jsonfuzz/corpus/%x", sha1.Sum(json)), json, 0777); err != nil { + if err := os.WriteFile(fmt.Sprintf("internal/fuzz/jsonfuzz/corpus/%x", sha1.Sum(json)), json, 0777); err != nil { log.Fatal(err) } } diff --git a/internal/cmd/generate-protos/main.go b/internal/cmd/generate-protos/main.go index 6724775c..e0ba3a66 100644 --- a/internal/cmd/generate-protos/main.go +++ b/internal/cmd/generate-protos/main.go @@ -11,7 +11,6 @@ import ( "flag" "fmt" "go/format" - "io/ioutil" "os" "os/exec" "path" @@ -126,7 +125,7 @@ func generateEditionsDefaults() { } func generateLocalProtos() { - tmpDir, err := ioutil.TempDir(repoRoot, "tmp") + tmpDir, err := os.MkdirTemp(repoRoot, "tmp") check(err) defer os.RemoveAll(tmpDir) @@ -197,7 +196,7 @@ func generateLocalProtos() { }...), "\n") b, err := format.Source([]byte(s)) check(err) - check(ioutil.WriteFile(filepath.Join(tmpDir, filepath.FromSlash(d.path+"/gen_test.go")), b, 0664)) + check(os.WriteFile(filepath.Join(tmpDir, filepath.FromSlash(d.path+"/gen_test.go")), b, 0664)) } } @@ -205,7 +204,7 @@ func generateLocalProtos() { } func generateRemoteProtos() { - tmpDir, err := ioutil.TempDir(repoRoot, "tmp") + tmpDir, err := os.MkdirTemp(repoRoot, "tmp") check(err) defer os.RemoveAll(tmpDir) @@ -466,14 +465,14 @@ func syncOutput(dstDir, srcDir string) { } func copyFile(dstPath, srcPath string) (changed bool) { - src, err := ioutil.ReadFile(srcPath) + src, err := os.ReadFile(srcPath) check(err) check(os.MkdirAll(filepath.Dir(dstPath), 0775)) - dst, _ := ioutil.ReadFile(dstPath) + dst, _ := os.ReadFile(dstPath) if bytes.Equal(src, dst) { return false } - check(ioutil.WriteFile(dstPath, src, 0664)) + check(os.WriteFile(dstPath, src, 0664)) return true } diff --git a/internal/cmd/generate-types/main.go b/internal/cmd/generate-types/main.go index 53f3721b..9a7460c9 100644 --- a/internal/cmd/generate-types/main.go +++ b/internal/cmd/generate-types/main.go @@ -11,7 +11,6 @@ import ( "flag" "fmt" "go/format" - "io/ioutil" "os" "os/exec" "path" @@ -248,13 +247,13 @@ func writeSource(file, src string) { absFile := filepath.Join(repoRoot, file) if run { - prev, _ := ioutil.ReadFile(absFile) + prev, _ := os.ReadFile(absFile) if !bytes.Equal(b, prev) { fmt.Println("#", file) - check(ioutil.WriteFile(absFile, b, 0664)) + check(os.WriteFile(absFile, b, 0664)) } } else { - check(ioutil.WriteFile(absFile+".tmp", b, 0664)) + check(os.WriteFile(absFile+".tmp", b, 0664)) defer os.Remove(absFile + ".tmp") cmd := exec.Command("diff", file, file+".tmp", "-N", "-u") diff --git a/internal/cmd/pbdump/pbdump.go b/internal/cmd/pbdump/pbdump.go index befb8310..b3ea3eb8 100644 --- a/internal/cmd/pbdump/pbdump.go +++ b/internal/cmd/pbdump/pbdump.go @@ -9,7 +9,7 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -111,14 +111,14 @@ func main() { // Read message input. var buf []byte if flag.NArg() == 0 { - b, err := ioutil.ReadAll(os.Stdin) + b, err := io.ReadAll(os.Stdin) if err != nil { log.Fatalf("ReadAll error: %v", err) } buf = b } for _, f := range flag.Args() { - b, err := ioutil.ReadFile(f) + b, err := os.ReadFile(f) if err != nil { log.Fatalf("ReadFile error: %v", err) } diff --git a/internal/filedesc/build_test.go b/internal/filedesc/build_test.go index 979b8ea1..8dd7323b 100644 --- a/internal/filedesc/build_test.go +++ b/internal/filedesc/build_test.go @@ -7,7 +7,7 @@ package filedesc_test import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "testing" "google.golang.org/protobuf/proto" @@ -33,7 +33,7 @@ func TestInit(t *testing.T) { want := &descriptorpb.FileDescriptorProto{} zb, _ := (&testpb.TestAllTypes{}).Descriptor() r, _ := gzip.NewReader(bytes.NewBuffer(zb)) - b, _ := ioutil.ReadAll(r) + b, _ := io.ReadAll(r) if err := proto.Unmarshal(b, want); err != nil { t.Fatal(err) } diff --git a/internal/fuzztest/fuzztest.go b/internal/fuzztest/fuzztest.go index 2b54eb59..5f0625cd 100644 --- a/internal/fuzztest/fuzztest.go +++ b/internal/fuzztest/fuzztest.go @@ -7,7 +7,6 @@ package fuzztest import ( "flag" - "io/ioutil" "os" "path/filepath" "sort" @@ -34,7 +33,7 @@ func Test(t *testing.T, fuzz func(b []byte) int) { sort.Strings(names) for _, name := range names { t.Run(name, func(t *testing.T) { - b, err := ioutil.ReadFile(filepath.Join(*corpus, name)) + b, err := os.ReadFile(filepath.Join(*corpus, name)) if err != nil { t.Fatal(err) } diff --git a/internal/impl/legacy_export_test.go b/internal/impl/legacy_export_test.go index e1d2c08b..a9ce6a75 100644 --- a/internal/impl/legacy_export_test.go +++ b/internal/impl/legacy_export_test.go @@ -7,7 +7,7 @@ package impl import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "math" "strings" "testing" @@ -30,7 +30,7 @@ func TestCompressGZIP(t *testing.T) { if err != nil { t.Errorf("unexpected gzip.NewReader error: %v", err) } - b, err := ioutil.ReadAll(zr) + b, err := io.ReadAll(zr) if err != nil { t.Errorf("unexpected ioutil.ReadAll error: %v", err) } diff --git a/internal/impl/legacy_file.go b/internal/impl/legacy_file.go index 9ab09108..b649f112 100644 --- a/internal/impl/legacy_file.go +++ b/internal/impl/legacy_file.go @@ -7,7 +7,7 @@ package impl import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "sync" "google.golang.org/protobuf/internal/filedesc" @@ -51,7 +51,7 @@ func legacyLoadFileDesc(b []byte) protoreflect.FileDescriptor { if err != nil { panic(err) } - b2, err := ioutil.ReadAll(zr) + b2, err := io.ReadAll(zr) if err != nil { panic(err) } diff --git a/internal/impl/legacy_file_test.go b/internal/impl/legacy_file_test.go index 66600eec..f08eb024 100644 --- a/internal/impl/legacy_file_test.go +++ b/internal/impl/legacy_file_test.go @@ -7,7 +7,7 @@ package impl_test import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "reflect" "testing" @@ -39,7 +39,7 @@ func mustLoadFileDesc(b []byte, _ []int) protoreflect.FileDescriptor { if err != nil { panic(err) } - b, err = ioutil.ReadAll(zr) + b, err = io.ReadAll(zr) if err != nil { panic(err) } diff --git a/internal/protolegacy/proto.go b/internal/protolegacy/proto.go index 96b44d91..7c091939 100644 --- a/internal/protolegacy/proto.go +++ b/internal/protolegacy/proto.go @@ -11,7 +11,7 @@ import ( "compress/gzip" "errors" "fmt" - "io/ioutil" + "io" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" @@ -48,7 +48,7 @@ func RegisterFile(s string, d []byte) { if err != nil { panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err)) } - b, err := ioutil.ReadAll(zr) + b, err := io.ReadAll(zr) if err != nil { panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err)) }