MCPcopy Create free account
hub / github.com/bufbuild/buf / getFileInfoAndDelegateIndex

Method getFileInfoAndDelegateIndex

private/bufpkg/bufmodule/module_read_bucket.go:859–897  ·  view source on GitHub ↗
(
	ctx context.Context,
	op string,
	path string,
)

Source from the content-addressed store, hash-verified

857}
858
859func (m *multiProtoFileModuleReadBucket[T, S]) getFileInfoAndDelegateIndex(
860 ctx context.Context,
861 op string,
862 path string,
863) (FileInfo, int, error) {
864 var fileInfos []FileInfo
865 var delegateIndexes []int
866 protoFileTracker := newProtoFileTracker()
867 for i, delegate := range m.delegates {
868 fileInfo, err := delegate.StatFileInfo(ctx, path)
869 if err != nil {
870 if errors.Is(err, fs.ErrNotExist) {
871 continue
872 }
873 return nil, 0, err
874 }
875 if fileInfo.FileType() != FileTypeProto {
876 continue
877 }
878 protoFileTracker.trackFileInfo(fileInfo)
879 fileInfos = append(fileInfos, fileInfo)
880 delegateIndexes = append(delegateIndexes, i)
881 }
882 // If we detected the same .proto file, this is an error.
883 if err := protoFileTracker.validate(); err != nil {
884 return nil, 0, err
885 }
886 switch len(fileInfos) {
887 case 0:
888 return nil, 0, &fs.PathError{Op: op, Path: path, Err: fs.ErrNotExist}
889 case 1:
890 return fileInfos[0], delegateIndexes[0], nil
891 default:
892 // If we detected a non-proto file duplicate, this means we constructed the multiProtoFileModuleReadBucket
893 // incorrectly, as we should not do union buckets for non-proto files. It is totally valid
894 // for LICENSE and README.md to be duplicated.
895 return nil, 0, newExistsMultipleModulesError(path, fileInfos...)
896 }
897}
898
899func (*multiProtoFileModuleReadBucket[T, S]) isModuleReadBucket() {}
900

Callers 3

GetFileMethod · 0.95
StatFileInfoMethod · 0.95

Calls 6

newProtoFileTrackerFunction · 0.85
trackFileInfoMethod · 0.80
StatFileInfoMethod · 0.65
FileTypeMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected