-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
127 lines (102 loc) · 2.64 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/comomac/kagami/client"
"github.com/comomac/kagami/core"
"github.com/comomac/kagami/server"
"github.com/ninja-software/terror"
)
func main() {
mode := flag.String("mode", "help", "mode to run. server, client, local, check")
hostIP := flag.String("hostIP", "", "server ip to host from or connect ip (server/client)")
dirPtr := flag.String("scanDir", ".", "dir to scan")
maxIDist := flag.Int("maxIDist", 3, "maximum image distance. 0-64")
maxADiff := flag.Int("maxADiff", 10, "maximum archive difference")
exactMatch := flag.Bool("exactMatch", false, "match using exact match")
flag.Parse()
switch *mode {
case "local":
// local mode
fmt.Println("mode: local")
if *dirPtr == "" {
fmt.Println("scanDir must be specified")
return
}
// create store dir for inode data
err := os.Mkdir(*dirPtr+"/store", 0755)
if err != nil && !os.IsExist(err) {
terror.Echo(err)
return
}
// list by files
// core.ListDir(*dirPtr)
// list by images
q := core.Queue{}
err = core.ListDirByQueue(*dirPtr, &q, false)
if err != nil {
terror.Echo(err)
return
}
fmt.Println("DONE")
return
case "server":
// server mode
fmt.Println("mode: server")
if *dirPtr == "" {
fmt.Println("scanDir must be specified")
return
}
// create store dir for inode data
err := os.Mkdir(*dirPtr+"/store", 0755)
if err != nil && !os.IsExist(err) {
log.Fatal(err)
}
err = server.Serve(*hostIP, *dirPtr)
if err != nil {
log.Fatal(err)
}
case "client":
// client mode
fmt.Println("mode: client")
err := client.Connect(*hostIP)
if err != nil {
log.Fatal(err)
}
case "check":
// check and find duplicate
if *dirPtr == "" {
fmt.Println("scanDir must be specified")
return
}
if *maxIDist > 64 || *maxIDist < 0 {
fmt.Println("invalid maxIDist. valid 0-64")
return
}
if *maxADiff < 0 {
fmt.Println("invalid maxADiff. valid >0")
return
}
fmt.Printf("maxIDist: %d maxADiff: %d exactMatch: %t\n", *maxIDist, *maxADiff, *exactMatch)
err := core.FindDup(*dirPtr+"/store", *maxIDist, *maxADiff, *exactMatch)
if err != nil {
log.Fatal(err)
}
case "help":
default:
printHelp()
}
}
func printHelp() {
fmt.Println(`Kagami - detect duplicate image in archive
modes:
server - holds archive and send images to client to create image sums
client - receive images and calculate image sums
local - calculate image sums locally
check - find archives with duplicate images
parameters:
scanDir - directory to scan archives
hostIP - server/client use. server: ip for server to host from. client: server ip to connect to`)
}