Make doublestar a little cleaner

This commit is contained in:
2025-03-27 17:21:13 +01:00
parent 3e818e61c7
commit 5c5fbac63f
2 changed files with 16 additions and 6 deletions

14
main.go
View File

@@ -226,10 +226,20 @@ func expandFilePatterns(patterns []string) ([]string, error) {
var files []string
filesMap := make(map[string]bool)
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("failed to get current working directory: %w", err)
}
for _, pattern := range patterns {
matches, _ := doublestar.Glob(os.DirFS("."), pattern)
matches, _ := doublestar.Glob(os.DirFS(cwd), pattern)
log.Printf("Found %d matches for pattern %s", len(matches), pattern)
for _, m := range matches {
if info, err := os.Stat(m); err == nil && !info.IsDir() && !filesMap[m] {
info, err := os.Stat(m)
if err != nil {
logger.Printf("Error getting file info for %s: %v", m, err)
continue
}
if !info.IsDir() && !filesMap[m] {
filesMap[m], files = true, append(files, m)
}
}