Implement doublestar globbing instead of file list
This commit is contained in:
22
main.go
22
main.go
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user