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

8
.vscode/launch.json vendored
View File

@@ -10,11 +10,11 @@
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"program": "${workspaceFolder}", "program": "${workspaceFolder}",
"cwd": "C:/Users/Administrator/Seafile/Games-Barotrauma",
"args": [ "args": [
"-mode=json", "LightComponent!anyrange=\"(!num)\"",
"$..name", "*4",
"v='pero'", "**/*.xml"
"test.json"
] ]
} }
] ]

14
main.go
View File

@@ -226,10 +226,20 @@ func expandFilePatterns(patterns []string) ([]string, error) {
var files []string var files []string
filesMap := make(map[string]bool) 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 { 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 { 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) filesMap[m], files = true, append(files, m)
} }
} }