Implement doublestar globbing instead of file list
This commit is contained in:
5
go.mod
5
go.mod
@@ -7,4 +7,7 @@ require (
|
||||
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
2
go.sum
@@ -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/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/go.mod h1:VkvE0mLn84L4aF8vCb6mafVajEb6QYMHl2ZJLn0mOGI=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
|
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