46 lines
770 B
Go
46 lines
770 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
// "strings"
|
|
)
|
|
|
|
func ExpandGlob(patterns []string) ([]string, error) {
|
|
var result []string
|
|
|
|
for _, pattern := range patterns {
|
|
|
|
if pattern == "*" {
|
|
files, err := filepath.Glob("**") // fallback
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result = append(result, files...)
|
|
continue
|
|
}
|
|
|
|
matches, err := filepath.Glob(pattern)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, m := range matches {
|
|
info, err := os.Stat(m)
|
|
if err != nil || info.IsDir() {
|
|
continue
|
|
}
|
|
result = append(result, m)
|
|
}
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func add(path string, seen map[string]struct{}, result *[]string) {
|
|
if _, ok := seen[path]; ok {
|
|
return
|
|
}
|
|
seen[path] = struct{}{}
|
|
*result = append(*result, path)
|
|
} |