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

Method WalkFileInfos

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

Source from the content-addressed store, hash-verified

343}
344
345func (b *moduleReadBucket) WalkFileInfos(
346 ctx context.Context,
347 fn func(FileInfo) error,
348 options ...WalkFileInfosOption,
349) error {
350 // Note that we must verify that at least one file in this ModuleReadBucket is
351 // a .proto file, per the documentation on Module.
352 protoFileTracker := newProtoFileTracker()
353
354 walkFileInfosOptions := newWalkFileInfosOptions()
355 for _, option := range options {
356 option(walkFileInfosOptions)
357 }
358 bucket, err := b.getBucket()
359 if err != nil {
360 return err
361 }
362
363 if !walkFileInfosOptions.onlyTargetFiles {
364 // We only want to call trackModule if we are walking all the files, not just
365 // the target files. By not calling trackModule outside of this if statement,
366 // we will not produce NoProtoFilesErrors, per the documentation on trackModule.
367 protoFileTracker.trackModule(b.module)
368 if err := bucket.Walk(
369 ctx,
370 "",
371 func(objectInfo storage.ObjectInfo) error {
372 fileInfo, err := b.getFileInfo(ctx, objectInfo)
373 if err != nil {
374 return err
375 }
376 protoFileTracker.trackFileInfo(fileInfo)
377 return fn(fileInfo)
378 },
379 ); err != nil {
380 return err
381 }
382 return protoFileTracker.validate()
383 }
384
385 // If we are walking all files, then we track the module if it is the target module
386 if b.module.IsTarget() {
387 protoFileTracker.trackModule(b.module)
388 }
389
390 targetFileWalkFunc := func(objectInfo storage.ObjectInfo) error {
391 fileInfo, err := b.getFileInfo(ctx, objectInfo)
392 if err != nil {
393 return err
394 }
395 protoFileTracker.trackFileInfo(fileInfo)
396 if !fileInfo.IsTargetFile() {
397 return nil
398 }
399 return fn(fileInfo)
400 }
401
402 // If we have target paths, we do not want to walk the whole bucket.

Callers

nothing calls this directly

Calls 11

getFileInfoMethod · 0.95
newProtoFileTrackerFunction · 0.85
newWalkFileInfosOptionsFunction · 0.85
optionStruct · 0.85
trackModuleMethod · 0.80
trackFileInfoMethod · 0.80
WalkMethod · 0.65
IsTargetMethod · 0.65
IsTargetFileMethod · 0.65
PathMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected