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

5
go.mod
View File

@@ -7,4 +7,7 @@ require (
github.com/corona10/goimagehash v1.1.0 github.com/corona10/goimagehash v1.1.0
) )
require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect require (
github.com/bmatcuk/doublestar/v4 v4.8.1
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
)

2
go.sum
View File

@@ -1,5 +1,7 @@
git.site.quack-lab.dev/dave/cylogger v1.2.2 h1:4xUXASEBlG9NiGxh7f57xHh9imW4unHzakIEpQoKC5E= git.site.quack-lab.dev/dave/cylogger v1.2.2 h1:4xUXASEBlG9NiGxh7f57xHh9imW4unHzakIEpQoKC5E=
git.site.quack-lab.dev/dave/cylogger v1.2.2/go.mod h1:VS9MI4Y/cwjCBZgel7dSfCQlwtAgHmfvixOoBgBhtKg= git.site.quack-lab.dev/dave/cylogger v1.2.2/go.mod h1:VS9MI4Y/cwjCBZgel7dSfCQlwtAgHmfvixOoBgBhtKg=
github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38=
github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/corona10/goimagehash v1.1.0 h1:teNMX/1e+Wn/AYSbLHX8mj+mF9r60R1kBeqE9MkoYwI= github.com/corona10/goimagehash v1.1.0 h1:teNMX/1e+Wn/AYSbLHX8mj+mF9r60R1kBeqE9MkoYwI=
github.com/corona10/goimagehash v1.1.0/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI= github.com/corona10/goimagehash v1.1.0/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=

22
main.go
View File

@@ -4,9 +4,11 @@ import (
"flag" "flag"
"image/jpeg" "image/jpeg"
"os" "os"
"path/filepath"
"sync" "sync"
logger "git.site.quack-lab.dev/dave/cylogger" logger "git.site.quack-lab.dev/dave/cylogger"
"github.com/bmatcuk/doublestar/v4"
"github.com/corona10/goimagehash" "github.com/corona10/goimagehash"
) )
@@ -17,7 +19,25 @@ func main() {
hashes := &sync.Map{} hashes := &sync.Map{}
logger.Info("Starting") logger.Info("Starting")
logger.Info("Threshold: %v", *thresh) 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{} wg := sync.WaitGroup{}
for _, file := range flag.Args() { for _, file := range flag.Args() {