ValidatePathsNormalizedValidatedUnique validates the file or directory paths are normalized and validated, and not duplicated.
(paths []string)
| 354 | // ValidatePathsNormalizedValidatedUnique validates the file or directory paths are normalized |
| 355 | // and validated, and not duplicated. |
| 356 | func 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 | } |
no test coverage detected
searching dependent graphs…