Implement doublestar globbing instead of file list

This commit is contained in:
2025-05-23 13:11:49 +02:00
parent 91df8aa4f4
commit 9b49cfa9a5
3 changed files with 27 additions and 2 deletions

22
main.go
View File

@@ -4,9 +4,11 @@ import (
"flag"
"image/jpeg"
"os"
"path/filepath"
"sync"
logger "git.site.quack-lab.dev/dave/cylogger"
"github.com/bmatcuk/doublestar/v4"
"github.com/corona10/goimagehash"
)
@@ -17,7 +19,25 @@ func main() {
hashes := &sync.Map{}
logger.Info("Starting")
logger.Info("Threshold: %v", *thresh)
logger.Info("Files: %d", len(flag.Args()))
logger.Info("Patterns: %d", len(flag.Args()))
files := make([]string, 0)
for _, pattern := range flag.Args() {
base, pattern := doublestar.SplitPattern(pattern)
logger.Debug("Globbing %q from %q", pattern, base)
matches, err := doublestar.Glob(os.DirFS(base), pattern)
if err != nil {
logger.Error("Failed to glob pattern: %v", err)
continue
}
logger.Debug("Glob %q in %q got %d matches", pattern, base, len(matches))
for _, match := range matches {
match = filepath.Join(base, match)
logger.Trace("Adding %q", match)
files = append(files, match)
}
}
logger.Info("Patterns expanded to %d files", len(files))
wg := sync.WaitGroup{}
for _, file := range flag.Args() {