-
Notifications
You must be signed in to change notification settings - Fork 92
/
directories.go
219 lines (187 loc) · 4.7 KB
/
directories.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package main
import (
"fmt"
"path/filepath"
"github.com/FactomProject/factomd/state"
survey "gopkg.in/AlecAivazis/survey.v1"
)
func SelectDirectory() {
var qs = []*survey.Question{
{
Name: "select",
Prompt: &survey.Select{
Message: "Choose a directory:",
Options: append([]string{"back"}, directories...),
Default: directories[0],
},
},
}
// the answers will be written to this struct
answers := struct {
Select string `survey:"select"`
}{}
// perform the questions
err := survey.Ask(qs, &answers)
if err != nil {
fmt.Println(err.Error())
return
}
if answers.Select == "back" {
return
}
files, err := filepath.Glob(filepath.Join(answers.Select, "*.block"))
if err != nil {
fmt.Println(err.Error())
return
}
for {
qs = []*survey.Question{
{
Name: "select",
Prompt: &survey.Select{
Message: "Choose a file:",
Options: append([]string{"back"}, files...),
Default: files[0],
},
},
}
// perform the questions
err = survey.Ask(qs, &answers)
if err != nil {
fmt.Println(err.Error())
return
}
if answers.Select == "back" {
break
}
OpenSingleFile(answers.Select)
}
SelectDirectory()
}
type WBSummary struct {
DBHash map[string][]string
AHash map[string][]string
FHash map[string][]string
ECHash map[string][]string
}
func NewWBSummary() *WBSummary {
wb := new(WBSummary)
wb.DBHash = make(map[string][]string)
wb.AHash = make(map[string][]string)
wb.FHash = make(map[string][]string)
wb.ECHash = make(map[string][]string)
return wb
}
func CompareDirectory() {
var qs3 = []*survey.Question{
{
Name: "select",
Prompt: &survey.Select{
Message: "Choose a block number to compare:",
Options: append([]string{"back"}, []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}...),
Default: directories[0],
},
},
}
// the answers will be written to this struct
answers := struct {
Select string `survey:"select"`
}{}
// perform the questions
err := survey.Ask(qs3, &answers)
if err != nil {
fmt.Println(err.Error())
return
}
if answers.Select == "back" {
return
}
summaries := NewWBSummary()
for _, d := range directories {
filename := filepath.Join(d, fmt.Sprintf("processed_dbstate_%s.block", answers.Select))
wb, err := state.ReadDBStateFromDebugFile(filename)
if err != nil {
fmt.Printf("%s could not be opened: %s\n", filename, err.Error())
continue
}
summaries.DBHash[wb.DBlock.GetKeyMR().String()] = append(summaries.DBHash[wb.DBlock.GetKeyMR().String()], filename)
k, _ := wb.ABlock.GetKeyMR()
summaries.AHash[k.String()] = append(summaries.AHash[k.String()], filename)
summaries.FHash[wb.FBlock.GetKeyMR().String()] = append(summaries.FHash[wb.FBlock.GetKeyMR().String()], filename)
k, _ = wb.ECBlock.GetFullHash()
summaries.ECHash[k.String()] = append(summaries.ECHash[k.String()], filename)
}
investigated := false
if len(summaries.DBHash) > 1 {
fmt.Println("Found more than 1 DBlockHash:")
investigated = PrintDiff(summaries.DBHash, investigated)
} else {
fmt.Println("Directory Blocks match")
}
if len(summaries.AHash) > 1 {
fmt.Println("Found more than 1 ABlockHash:")
investigated = PrintDiff(summaries.AHash, investigated)
} else {
fmt.Println("Admin Blocks match")
}
if len(summaries.FHash) > 1 {
fmt.Println("Found more than 1 FBlockHash:")
investigated = PrintDiff(summaries.FHash, investigated)
} else {
fmt.Println("Factoid Blocks match")
}
if len(summaries.ECHash) > 1 {
fmt.Println("Found more than 1 ECBlockHash:")
investigated = PrintDiff(summaries.ECHash, investigated)
} else {
fmt.Println("Entry Credit Blocks match")
}
//CompareDirectory()
}
func PrintDiff(m map[string][]string, investigated bool) bool {
investigate := len(m) > 1 && !investigated
comparelist := []string{}
for k, v := range m {
fmt.Printf(" %d match %s\n", len(v), k)
comparelist = append(comparelist, v[0])
for _, d := range v {
fmt.Printf(" - %s\n", d)
}
}
if investigate {
option := false
prompt := &survey.Confirm{
Message: "Do you want to investigate?",
}
survey.AskOne(prompt, &option, nil)
if option {
for {
var qs = []*survey.Question{
{
Name: "select",
Prompt: &survey.Select{
Message: "Choose a file:",
Options: append([]string{"back"}, comparelist...),
Default: comparelist[0],
},
},
}
answers := struct {
Select string `survey:"select"`
}{}
// perform the questions
err := survey.Ask(qs, &answers)
if err != nil {
fmt.Println("Error in printdiff", err.Error())
return true
}
if answers.Select == "back" {
return true
}
OpenSingleFile(answers.Select)
}
}
return true
}
return investigated
}