a version with known bug fixed but not sure any more obscure ones

This commit is contained in:
2026-05-16 03:55:00 +08:00
parent 615c324d9b
commit 3012507fcc
4 changed files with 160 additions and 58 deletions
+6 -38
View File
@@ -3,52 +3,20 @@ package utils
import (
"os"
"path/filepath"
"strings"
// "strings"
)
func ExpandGlob(patterns []string) ([]string, error) {
var result []string
seen := make(map[string]struct{})
for _, pattern := range patterns {
if pattern == "*" {
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if info.IsDir() {
return nil
}
add(path, seen, &result)
return nil
})
continue
}
isRecursive := strings.Contains(pattern, "**")
if isRecursive {
root := strings.Split(pattern, "**")[0]
if root == "" {
root = "."
files, err := filepath.Glob("**") // fallback
if err != nil {
return nil, err
}
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return nil
}
matched, _ := filepath.Match(
strings.Replace(pattern, "**", "*", 1),
path,
)
if matched {
add(path, seen, &result)
}
return nil
})
result = append(result, files...)
continue
}
@@ -62,7 +30,7 @@ func ExpandGlob(patterns []string) ([]string, error) {
if err != nil || info.IsDir() {
continue
}
add(m, seen, &result)
result = append(result, m)
}
}