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

Function filterImage

private/buf/bufctl/controller.go:1425–1472  ·  view source on GitHub ↗

WE DO NOT FILTER IF WE ALREADY FILTERED ON BUILDING OF A WORKSPACE Also, paths are still external paths at this point if this came from a workspace TODO FUTURE: redo functionOptions, this is a mess

(
	image bufimage.Image,
	functionOptions *functionOptions,
	imageCameFromAWorkspace bool,
)

Source from the content-addressed store, hash-verified

1423// Also, paths are still external paths at this point if this came from a workspace
1424// TODO FUTURE: redo functionOptions, this is a mess
1425func filterImage(
1426 image bufimage.Image,
1427 functionOptions *functionOptions,
1428 imageCameFromAWorkspace bool,
1429) (bufimage.Image, error) {
1430 newImage := image
1431 var err error
1432 if functionOptions.imageExcludeImports {
1433 newImage = bufimage.ImageWithoutImports(newImage)
1434 }
1435 includeTypes := functionOptions.imageIncludeTypes
1436 excludeTypes := functionOptions.imageExcludeTypes
1437 if len(includeTypes) > 0 || len(excludeTypes) > 0 {
1438 newImage, err = bufimageutil.FilterImage(
1439 newImage,
1440 bufimageutil.WithIncludeTypes(includeTypes...),
1441 bufimageutil.WithExcludeTypes(excludeTypes...),
1442 bufimageutil.WithMutateInPlace(),
1443 )
1444 if err != nil {
1445 return nil, err
1446 }
1447 }
1448 if !imageCameFromAWorkspace {
1449 if len(functionOptions.targetPaths) > 0 || len(functionOptions.targetExcludePaths) > 0 {
1450 // bufimage expects normalized paths, so we need to normalize the paths
1451 // from functionOptions before passing them through.
1452 normalizedTargetPaths := make([]string, 0, len(functionOptions.targetPaths))
1453 normalizedExcludePaths := make([]string, 0, len(functionOptions.targetExcludePaths))
1454 for _, targetPath := range functionOptions.targetPaths {
1455 normalizedTargetPaths = append(normalizedTargetPaths, normalpath.Normalize(targetPath))
1456 }
1457 for _, excludePath := range functionOptions.targetExcludePaths {
1458 normalizedExcludePaths = append(normalizedExcludePaths, normalpath.Normalize(excludePath))
1459 }
1460 // TODO FUTURE: allowNotExist? Also, does this affect lint or breaking?
1461 newImage, err = bufimage.ImageWithOnlyPathsAllowNotExist(
1462 newImage,
1463 normalizedTargetPaths,
1464 normalizedExcludePaths,
1465 )
1466 if err != nil {
1467 return nil, err
1468 }
1469 }
1470 }
1471 return newImage, nil
1472}
1473
1474func newStorageosProvider(disableSymlinks bool) storageos.Provider {
1475 var options []storageos.ProviderOption

Callers 3

PutImageMethod · 0.70
getImageForMessageRefMethod · 0.70
buildImageMethod · 0.70

Calls 7

ImageWithoutImportsFunction · 0.92
FilterImageFunction · 0.92
WithIncludeTypesFunction · 0.92
WithExcludeTypesFunction · 0.92
WithMutateInPlaceFunction · 0.92
NormalizeFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…