func matchingFileExists()

in code/go/internal/validator/folder_item_spec.go [16:38]


func matchingFileExists(spec spectypes.ItemSpec, files []fs.DirEntry) (bool, error) {
	if spec.Name() != "" {
		for _, file := range files {
			_, fileName := checkLink(file.Name())
			if fileName == spec.Name() {
				return spec.IsDir() == file.IsDir(), nil
			}
		}
	} else if spec.Pattern() != "" {
		for _, file := range files {
			_, fileName := checkLink(file.Name())
			isMatch, err := regexp.MatchString(spec.Pattern(), fileName)
			if err != nil {
				return false, fmt.Errorf("invalid folder item spec pattern: %w", err)
			}
			if isMatch {
				return spec.IsDir() == file.IsDir(), nil
			}
		}
	}

	return false, nil
}