/
verify.go
77 lines (71 loc) · 1.75 KB
/
verify.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
package fourbytes
import (
"fmt"
"os"
"path"
)
func logError(filename string, err string) {
fmt.Println("[", filename, "]:", err)
}
// Verify checks if the files written match the data
func Verify(chunks *map[string]mapRecord, outDir string) {
done := 0
for filePath, record := range *chunks {
done++
if done%10000 == 0 {
fmt.Printf("%d...\n", done)
}
if len(record.sigRecords) == 0 {
logError(filePath, "empty")
continue
}
file, err := os.OpenFile(path.Join(outDir, filePath), os.O_RDONLY, 0)
if err != nil {
logError(filePath, err.Error())
file.Close()
continue
}
// read data from the file
sigs, strs, err := readAll(file)
if err != nil {
logError(filePath, err.Error())
file.Close()
continue
}
// check lengths
got := len(record.sigRecords)
if len(sigs) != got {
logError(filePath, fmt.Sprintf("wrong number of sigs. Got %d, expected %d", got, len(sigs)))
}
got = len(record.strRecords)
if len(strs) != got {
logError(filePath, fmt.Sprintf("wrong number of strings. Got %d, expected %d", got, len(strs)))
}
// These take lots of time
// for _, sigRecord := range record.sigRecords {
// found := false
// for _, sig := range sigs {
// if sig.Signature.Hex() == sigRecord.Signature.Hex() {
// found = true
// break
// }
// }
// if !found {
// logError(filePath, fmt.Sprintf("Signature '%s' missing", sigRecord.Signature.Hex()))
// }
// }
// for _, strRecord := range record.strRecords {
// found := false
// for _, str := range strs {
// if str.Value == strRecord.Value {
// found = true
// break
// }
// }
// if !found {
// logError(filePath, fmt.Sprintf("String '%s' missing", strRecord.Value))
// }
// }
file.Close()
}
}