-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmd.go
56 lines (47 loc) · 964 Bytes
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"os"
"time"
"github.com/rivo/duplo"
)
func cmdMain() {
// default is to accept sprite directory and output csv of all matches
path := os.Args[1]
fmt.Fprintln(os.Stderr, "Outputting duplicates to csv")
f, err := os.Create("duplicates.csv")
if err != nil {
panic(err)
}
defer f.Close()
// output to stdout
a := api{}
a.cfg.DBFilename = "df-hashstore.db"
hdFunc := func(checksum string, matches duplo.Matches) {
if len(matches) > 0 {
match := matches[0]
fmt.Fprintf(f, "%s,%s,%.f\n", checksum, match.ID.(string), -match.Score)
fmt.Printf("%s - %s [%.f]\n", checksum, match.ID.(string), -match.Score)
}
}
c := make(chan bool, 1)
go func() {
err = a.processFiles(path, hdFunc)
if err != nil {
panic(err)
}
c <- true
}()
for {
select {
case <-c:
return
default:
_, err := os.Stat(".stop")
if err == nil {
a.stopping = true
}
time.Sleep(5 * time.Second)
}
}
}