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

Method WalkFileInfos

private/bufpkg/bufmodule/module_read_bucket.go:806–845  ·  view source on GitHub ↗
(
	ctx context.Context,
	fn func(FileInfo) error,
	options ...WalkFileInfosOption,
)

Source from the content-addressed store, hash-verified

804}
805
806func (m *multiProtoFileModuleReadBucket[T, S]) WalkFileInfos(
807 ctx context.Context,
808 fn func(FileInfo) error,
809 options ...WalkFileInfosOption,
810) error {
811 seenPathToFileInfo := make(map[string]FileInfo)
812 protoFileTracker := newProtoFileTracker()
813 for _, delegate := range m.delegates {
814 if err := delegate.WalkFileInfos(
815 ctx,
816 func(fileInfo FileInfo) error {
817 if fileInfo.FileType() != FileTypeProto {
818 return nil
819 }
820 path := fileInfo.Path()
821 protoFileTracker.trackFileInfo(fileInfo)
822 if existingFileInfo, ok := seenPathToFileInfo[path]; ok {
823 // If we detected the same .proto file, this is an error.
824 if err := protoFileTracker.validate(); err != nil {
825 return err
826 }
827 // If we detected a non-proto file duplicate, this means we constructed the multiProtoFileModuleReadBucket
828 // incorrectly, as we should not do union buckets for non-proto files. It is totally valid
829 // for LICENSE and README.md to be duplicated.
830 //
831 // This does not return all paths that are matching, unlike GetFile and StatFileInfo.
832 // We do not want to continue iterating, as calling WalkFileInfos on the same path
833 // could cause errors downstream as callers expect a single call per path.
834 return newExistsMultipleModulesError(path, existingFileInfo, fileInfo)
835 }
836 seenPathToFileInfo[path] = fileInfo
837 return fn(fileInfo)
838 },
839 options...,
840 ); err != nil {
841 return err
842 }
843 }
844 return nil
845}
846
847func (m *multiProtoFileModuleReadBucket[T, S]) ShouldBeSelfContained() bool {
848 return m.shouldBeSelfContained

Callers

nothing calls this directly

Calls 7

newProtoFileTrackerFunction · 0.85
trackFileInfoMethod · 0.80
WalkFileInfosMethod · 0.65
FileTypeMethod · 0.65
PathMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected