Skip to content

Commit

Permalink
internal/proto: set filename in FileDescriptorProto when missing
Browse files Browse the repository at this point in the history
Some old descriptors don't include a filename. When missing, set it from
the filename provided to proto.RegisterFile.

Fixes a number of warnings in the google.golang.org/protobuf tests
stemming from the legacy generated files:

	WARNING: proto: file "" is already registered
	A future release of proto will panic on registration conflicts.

Change-Id: I4f7c9e4a9ecb4d2a71073b0a373ec0c800e2ec66
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/184078
Reviewed-by: Joe Tsai <[email protected]>
  • Loading branch information
neild committed Jun 27, 2019
1 parent 1ee46df commit 346ae1c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/proto/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func RegisterFile(s filePath, d fileDescGZIP) {
if err := protoV2.Unmarshal(b, &pb); err != nil {
panic(fmt.Sprintf("proto: unmarshal failure: %v", err))
}
// Some old descriptors don't include the filename.
if pb.Name == nil {
pb.Name = &s
}

// Convert the raw descriptor to a structured file descriptor.
fd, err := protodesc.NewFile(&pb, nil)
Expand Down

0 comments on commit 346ae1c

Please sign in to comment.