Is it permitted for multiple files to have the same file path?

48 views
Skip to first unread message

Bingo Kang

unread,
Nov 8, 2022, 6:56:19 AM11/8/22
to Protocol Buffers
In google.golang.org/protobuf v1.28.1,  reflect/protoregistry/registry.go, comment says:

// It is permitted for multiple files to have the same file path.
func (r *Files) RegisterFile(file protoreflect.FileDescriptor) error {
  ...
}

But as the code says: 

path := file.Path()
if prev := r.filesByPath[path]; len(prev) > 0 {
  r.checkGenProtoConflict(path)
  err := errors.New("file %q is already registered", file.Path())
  err = amendErrorWithCaller(err, prev[0], file)
  if !(r == GlobalFiles && ignoreConflict(file, err)) {
    return err
  }
}

It seems that the code and the comment is not the same.
Please, anyone knows why?

Bingo Kang

unread,
Nov 8, 2022, 6:58:26 AM11/8/22
to Protocol Buffers
As the code says, it is not permitted for multiple files to have the same file path.
But as the comment says, it is permitted for multiple files to have the same file path.
I'm so confused...... : (

Adam Cozzette

unread,
Nov 8, 2022, 9:27:36 AM11/8/22
to Bingo Kang, Protocol Buffers
I would say having multiple files with the same path is asking for trouble and shouldn't be considered valid. On the other hand, I wouldn't be surprised if there is code out there that attempts to tolerate this situation anyway, maybe to accommodate legacy code. I'm not sure what this particular Go code you linked to is trying to do, though.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/5edee73c-ec5e-46c5-83da-1fda47b9540bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages