-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdecision.go
More file actions
82 lines (73 loc) · 2.16 KB
/
decision.go
File metadata and controls
82 lines (73 loc) · 2.16 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
package main
import (
"log"
"sync/atomic"
)
type attrStatus string
const (
// the stored xattr is missing
attrMiss attrStatus = "missing"
// the stored xattr is different than the calculated value
attrDiff attrStatus = "different"
// the stored xattr is equal to the calculated value
attrSame attrStatus = "same"
)
// decisionWithCount is used to hold both the name of
// the decision and the count of how often it was hit.
type decisionWithCount struct {
atomic.Uint64
name string
}
func (d *decisionWithCount) String() string {
return d.name
}
type decisions struct {
ok decisionWithCount
corrupt decisionWithCount
timechange decisionWithCount
outdated decisionWithCount
new decisionWithCount
}
var stats = struct {
total atomic.Uint64
errorsNotRegular atomic.Uint64
errorsOpening atomic.Uint64
errorsWritingXattr atomic.Uint64
errorsOther atomic.Uint64
inprogress atomic.Uint64
removed atomic.Uint64
decisions decisions
}{
decisions: decisions{
ok: decisionWithCount{name: "ok"},
corrupt: decisionWithCount{name: "corrupt"},
timechange: decisionWithCount{name: "timechange"},
outdated: decisionWithCount{name: "outdated"},
new: decisionWithCount{name: "new"},
},
}
var decisionTable = []struct {
tsStatus attrStatus
sha256Status attrStatus
decision *decisionWithCount
}{
// ts sha256 decision
{attrSame, attrSame, &stats.decisions.ok},
{attrSame, attrDiff, &stats.decisions.corrupt},
{attrSame, attrMiss, &stats.decisions.new}, // or outdated?
{attrDiff, attrSame, &stats.decisions.timechange},
{attrDiff, attrDiff, &stats.decisions.outdated},
{attrDiff, attrMiss, &stats.decisions.outdated},
{attrMiss, attrSame, &stats.decisions.timechange},
{attrMiss, attrDiff, &stats.decisions.outdated},
{attrMiss, attrMiss, &stats.decisions.new},
}
func lookupDecision(tsStatus, sha256Status attrStatus) *decisionWithCount {
for _, v := range decisionTable {
if v.tsStatus == tsStatus && v.sha256Status == sha256Status {
return v.decision
}
}
log.Panicf("No decision for tsStatus=%v sha256Status=%v", tsStatus, sha256Status)
return nil
}