func SkipPath()

in iterator/iterator.go [82:121]


func SkipPath(path safepath.Path, info fs.FileInfo) (bool, error) {

	// TODO: This could be built with a list of rules that we pass into the
	// iterator, so that it could be configurable as needed.

	if !path.IsAbs() { // the walk func gives us absolutes
		return false, fmt.Errorf("path %s was not absolute", path.String())
	}

	if info.IsDir() { // path.IsDir()
		absDir, ok := path.(safepath.AbsDir)
		if !ok { // should not happen unless bug
			return false, fmt.Errorf("expected AbsDir")
		}

		for _, dir := range SkipDirPaths {
			relDir := safepath.UnsafeParseIntoRelDir(dir)
			if absDir.HasDir(relDir) {
				return true, interfaces.SkipDir
			}
		}

		return false, nil // don't skip
	}

	absFile, ok := path.(safepath.AbsFile)
	if !ok { // should not happen unless bug
		return false, fmt.Errorf("expected AbsFile")
	}

	for _, ext := range SkipPathExtensions {
		// Make sure we have at least one char in the file name (x.foo)
		// and insensitive match on extensions like .foo that we skip.
		if absFile.HasExtInsensitive(ext) && len(ext) != len(absFile.Path()) { // case insensitive
			return true, nil
		}
	}

	return false, nil // don't skip
}