func FileMatches()

in src/go/pkg/cachewarmer/path.go [19:44]


func FileMatches(inclusionList []string, exclusionList []string, maxFileSizeBytes int64, filename string, filesize int64) bool {
	// if the lists are empty, include everything
	if len(inclusionList) == 0 && len(exclusionList) == 0 && maxFileSizeBytes == 0 {
		return true
	}

	if maxFileSizeBytes != 0 && filesize > maxFileSizeBytes {
		return false
	}

	// exclusion takes priority
	for _, excludeStr := range exclusionList {
		if matched, err := filepath.Match(excludeStr, filename); err == nil && matched == true {
			return false
		}
	}

	// inclusion
	for _, includeStr := range inclusionList {
		if matched, err := filepath.Match(includeStr, filename); err == nil && matched == true {
			return true
		}
	}
	// only return true if there is a non-empty exclusion list, and empty inclusion list
	return len(inclusionList) == 0 && len(exclusionList) > 0
}