Documentation
¶
Index ¶
- func FilterFS(fsys fs.FS, filters ...FilterFunc) ([]string, error)
- func FilterPaths(paths []string, filters ...FilterFunc) ([]string, error)
- func ListEntries(dir string, filters ...FilterFunc) ([]string, error)
- func ListPathInDirSortedByComponents(searchDir string, relPath bool) ([]string, error)
- func SortPathsByComponents(paths []string) ([]string, error)
- type BySortablePathComponents
- type FilterFunc
- func BaseFilter(base string, allowed bool) FilterFunc
- func ComponentFilter(component string, allowed bool) FilterFunc
- func ComponentWithExtensionFilter(ext string, allowed bool) FilterFunc
- func DirectoryContainsFileFilter(fsys fs.FS, fileName string) FilterFunc
- func ExtensionFilter(ext string, allowed bool) FilterFunc
- func FileContainsFilter(fsys fs.FS, content string) FilterFunc
- func InDirectoryFilter(dir string, allowed bool) FilterFunc
- func IsDirectoryFilter(allowed bool) FilterFunc
- func RegexpFilter(pattern string, allowed bool) FilterFunc
- func SkipDirectoryNameFilter(dirName string) FilterFunc
- type PathChecker
- type PathModifier
- type PathProvider
- type SortablePath
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterFS ¶
func FilterFS(fsys fs.FS, filters ...FilterFunc) ([]string, error)
FilterFS walks fsys recursively and returns every path for which all filters return true. Paths are slash-separated and relative to fsys.
func FilterPaths ¶
func FilterPaths(paths []string, filters ...FilterFunc) ([]string, error)
FilterPaths applies filters to an explicit list of OS paths and returns the ones that pass every filter, preserving input order. Each path is stat-ed opportunistically so filters that consult fs.DirEntry (e.g. IsDirectoryFilter) work; paths that do not exist on disk are still fed to the filters with a nil DirEntry, matching v1's purely lexical behavior for path-only filters. Stat errors other than "not exist" surface to the caller.
This adapter preserves the v1 go-utils pathutil.FilterPaths signature so callers can migrate by import-path rename only. Prefer FilterFS in new code.
func ListEntries ¶
func ListEntries(dir string, filters ...FilterFunc) ([]string, error)
ListEntries lists the immediate children of dir, applies filters, and returns the matching entries as absolute paths. It is non-recursive.
This adapter preserves the v1 go-utils pathutil.ListEntries signature so callers can migrate by import-path rename only. Prefer FilterFS on an fs.FS in new code.
func ListPathInDirSortedByComponents ¶
ListPathInDirSortedByComponents walks searchDir recursively and returns every path found, sorted by directory depth. If relPath is true the paths are returned relative to searchDir.
func SortPathsByComponents ¶
SortPathsByComponents returns paths sorted by directory depth.
Types ¶
type BySortablePathComponents ¶
type BySortablePathComponents []SortablePath
BySortablePathComponents sorts SortablePath values by component depth (shallowest first), breaking ties alphabetically on the base name and falling back to the absolute and original paths to keep the order deterministic when same-depth same-base entries exist.
func (BySortablePathComponents) Len ¶
func (s BySortablePathComponents) Len() int
func (BySortablePathComponents) Less ¶
func (s BySortablePathComponents) Less(i, j int) bool
func (BySortablePathComponents) Swap ¶
func (s BySortablePathComponents) Swap(i, j int)
type FilterFunc ¶
FilterFunc decides whether an entry produced by an fs.FS walk should be kept. The path is slash-separated and rooted at the fs root ("." for the root itself). Returning fs.SkipDir as the error skips the current directory's subtree.
func BaseFilter ¶
func BaseFilter(base string, allowed bool) FilterFunc
BaseFilter matches entries whose base name equals base (case-insensitive). When allowed is false the match is inverted.
func ComponentFilter ¶
func ComponentFilter(component string, allowed bool) FilterFunc
ComponentFilter matches entries whose path contains component as one of its slash-separated components.
func ComponentWithExtensionFilter ¶
func ComponentWithExtensionFilter(ext string, allowed bool) FilterFunc
ComponentWithExtensionFilter matches entries whose path has at least one component with the given extension (case-insensitive, leading dot included, e.g. ".xcodeproj").
func DirectoryContainsFileFilter ¶
func DirectoryContainsFileFilter(fsys fs.FS, fileName string) FilterFunc
DirectoryContainsFileFilter matches directories that contain a regular file named fileName. fsys is used to stat the candidate path.
func ExtensionFilter ¶
func ExtensionFilter(ext string, allowed bool) FilterFunc
ExtensionFilter matches entries whose extension equals ext (case-insensitive, leading dot included, e.g. ".txt").
func FileContainsFilter ¶
func FileContainsFilter(fsys fs.FS, content string) FilterFunc
FileContainsFilter matches regular files whose contents include content. Directories never match.
func InDirectoryFilter ¶
func InDirectoryFilter(dir string, allowed bool) FilterFunc
InDirectoryFilter matches entries whose direct parent directory equals dir.
func IsDirectoryFilter ¶
func IsDirectoryFilter(allowed bool) FilterFunc
IsDirectoryFilter matches entries based on whether they are directories.
func RegexpFilter ¶
func RegexpFilter(pattern string, allowed bool) FilterFunc
RegexpFilter matches entries whose path contains a match for pattern. The pattern is compiled once when the filter is constructed.
func SkipDirectoryNameFilter ¶
func SkipDirectoryNameFilter(dirName string) FilterFunc
SkipDirectoryNameFilter keeps every non-directory entry. When it encounters a directory whose base name matches dirName (case-insensitive) it returns fs.SkipDir so the whole subtree is skipped.
type PathChecker ¶
type PathChecker interface {
IsPathExists(pth string) (bool, error)
IsDirExists(pth string) (bool, error)
}
PathChecker ...
type PathModifier ¶
type PathModifier interface {
AbsPath(pth string) (string, error)
EscapeGlobPath(path string) string
}
PathModifier ...
type PathProvider ¶
type PathProvider interface {
CreateTempDir(prefix string) (string, error)
Glob(pattern string) (matches []string, err error)
}
PathProvider ...
type SortablePath ¶
SortablePath pairs a path with its absolute form and component breakdown, enabling sorts that compare entries by directory depth.
func NewSortablePath ¶
func NewSortablePath(pth string) (SortablePath, error)
NewSortablePath expands pth to its absolute form and splits it into non-empty components suitable for depth-based sorting.