-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (80 loc) · 2.13 KB
/
main.go
File metadata and controls
91 lines (80 loc) · 2.13 KB
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
package main
import (
"flag"
"log"
"github.com/sevlyar/go-daemon"
)
type Record struct {
Bucket string
Path string // file path relative to Bucket root dir
AbsPath string // absolute file path on local disk
Checksum string
}
var (
asDaemon = flag.Bool("d", false, "run as daemon")
ct = flag.Bool("continue", false, "continue previous compensation")
)
func main() {
flag.Parse()
command := flag.Arg(0)
config, err := loadConfig("./config.yml")
if err != nil {
log.Printf("can't load config file with error: %v", err)
return
}
if *asDaemon {
cntxt := &daemon.Context{
PidFileName: "diffdir.pid",
PidFilePerm: 0644,
LogFileName: "diffdir.log",
LogFilePerm: 0640,
WorkDir: "./",
Umask: 027,
}
d, err := cntxt.Reborn()
if err != nil {
log.Fatal("Unable to run: ", err)
}
if d != nil {
return
}
defer cntxt.Release()
log.Print("- - - - - - - - - - - - - - -")
}
if command == "diff" {
diffFrom2 := flag.Arg(1)
if diffFrom2 == "" {
log.Fatalf("please input a filepath to diff, for example, diffdirs diff source.db")
return
}
diff(config, diffFrom2)
} else if command == "missize" {
diffResult := flag.Arg(1)
if diffResult == "" {
log.Fatalf("please input the filepath to diff result, for example, diffdirs missize diffresult.csv")
return
}
CountMismatchSize(diffResult, config)
} else if command == "miscount" {
diffResult := flag.Arg(1)
if diffResult == "" {
log.Fatalf("please input the filepath to diff result, for example, diffdirs missize diffresult.csv")
return
}
CountMismatchCount(diffResult, config)
} else if command == "compensate" {
diffResult := flag.Arg(1)
compensation := flag.Arg(2)
other := flag.Arg(3)
if diffResult == "" || compensation == "" || other != "" {
log.Fatalf("please input diff result path and compensate command, for example\ndiffdirs compensate diffresult.csv \"cp {ABSPATH} {BUCKET}/{PATH}\"")
return
}
Compensate(config, diffResult, compensation, *ct)
} else if command == "" {
generate(config)
} else {
log.Fatalf("unknown command %s", command)
}
log.Print("program finished")
}