Name extendedGlob() anonymous functions

Moves inline function definitions out of the function.
Helps with code readability.

Signed-off-by: Sebastian Soto <ssoto@redhat.com>
This commit is contained in:
Sebastian Soto 2025-07-03 19:35:21 -04:00
parent 1b5cdd50fa
commit a3dcd82d96
No known key found for this signature in database
GPG Key ID: 3322E2CC6B572FA0
1 changed files with 60 additions and 56 deletions

View File

@ -51,7 +51,20 @@ func init() {
// will be concatenated.
// The matched paths are returned in lexical order, which makes the output deterministic.
func extendedGlob(pattern string) (matches []string, err error) {
subdirs := func(dir string) []string {
patterns := expandPatterns(pattern)
for _, pattern := range patterns {
theseMatches, err := filepath.Glob(pattern)
if err != nil {
return nil, err
}
matches = append(matches, theseMatches...)
}
sort.Strings(matches)
return matches, nil
}
// subDirs returns a recursive search of all directories under the given dir
func subDirs(dir string) []string {
var subdirectories []string
if err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
@ -68,7 +81,9 @@ func extendedGlob(pattern string) (matches []string, err error) {
}
return subdirectories
}
expandPatterns := func(pattern string) []string {
// expandPatterns fans out a glob pattern so that "**" is expanded to all possible subdirectory paths at that location.
func expandPatterns(pattern string) []string {
components := []string{}
dir := pattern
file := ""
@ -84,7 +99,7 @@ func extendedGlob(pattern string) (matches []string, err error) {
var nextPatterns []string
if components[i] == "**" {
for _, parent := range patterns {
nextSubdirs := subdirs(parent)
nextSubdirs := subDirs(parent)
for _, nextSubdir := range nextSubdirs {
nextPatterns = append(nextPatterns, filepath.Join(parent, nextSubdir))
}
@ -107,17 +122,6 @@ func extendedGlob(pattern string) (matches []string, err error) {
}
return patterns
}
patterns := expandPatterns(pattern)
for _, pattern := range patterns {
theseMatches, err := filepath.Glob(pattern)
if err != nil {
return nil, err
}
matches = append(matches, theseMatches...)
}
sort.Strings(matches)
return matches, nil
}
// isArchivePath returns true if the specified path can be read like a (possibly
// compressed) tarball.