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

Function ValidatePathsNormalizedValidatedUnique

private/pkg/normalpath/normalpath.go:356–375  ·  view source on GitHub ↗

ValidatePathsNormalizedValidatedUnique validates the file or directory paths are normalized and validated, and not duplicated.

(paths []string)

Source from the content-addressed store, hash-verified

354// ValidatePathsNormalizedValidatedUnique validates the file or directory paths are normalized
355// and validated, and not duplicated.
356func ValidatePathsNormalizedValidatedUnique(paths []string) error {
357 pathMap := make(map[string]struct{}, len(paths))
358 for _, path := range paths {
359 if path == "" {
360 return errors.New("path is empty")
361 }
362 normalized, err := NormalizeAndValidate(path)
363 if err != nil {
364 return fmt.Errorf("path had normalization error: %w", err)
365 }
366 if path != normalized {
367 return fmt.Errorf("path %s was not normalized to %s", path, normalized)
368 }
369 if _, ok := pathMap[path]; ok {
370 return fmt.Errorf("duplicate path: %s", path)
371 }
372 pathMap[path] = struct{}{}
373 }
374 return nil
375}

Callers 1

imageWithOnlyPathsFunction · 0.92

Calls 1

NormalizeAndValidateFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…