/
workerEnd.go
75 lines (62 loc) · 2.2 KB
/
workerEnd.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
package main
import (
"encoding/hex"
"sync"
"time"
)
var workerEndJobs chan job
var workerEndJobswg sync.WaitGroup
func initWorkerEnd() {
workerCountEnd := config.WorkerCount
workerEndJobs = make(chan job, workerCountEnd)
workerEndJobswg.Add(workerCountEnd)
for i := 0; i < workerCountEnd; i++ {
go workerEnd()
}
}
func workerEnd() {
defer workerEndJobswg.Done()
for currentJob := range workerEndJobs {
err := func() error {
time_start := time.Now()
Trace.Printf("%v: End Processing...\n", currentJob.path)
for checksumAlgo := range currentJob.hashers {
currentHash := hex.EncodeToString(currentJob.hashers[checksumAlgo].Sum(nil))
checksumValue := GetChecksumXattr(currentJob.path, checksumAlgo)
// If the checksum is missing, just store it
if len(checksumValue) == 0 {
SetMTimeXattr(currentJob.path, currentJob.mtime)
SetChecksumXattr(currentJob.path, checksumAlgo, currentHash)
continue
}
// Do we match? Yay!
if currentHash == checksumValue {
continue
}
// No match, but the mtime was updated and the user requested that we update
// if this happens
if currentJob.mtime > currentJob.checksumMTime && config.UpdateOnNewMTime {
Warn.Printf("%v: Updating checksum due to updated mtime\n", currentJob.path)
SetMTimeXattr(currentJob.path, currentJob.mtime)
SetChecksumXattr(currentJob.path, checksumAlgo, currentHash)
continue
}
// If this goes backwards, we're kinda confused
if currentJob.mtime < currentJob.checksumMTime && config.UpdateOnNewMTime {
Error.Printf("%v: Failed to update checksum due to mtime reversing\n", currentJob.path)
}
// Sadness abounds!
Error.Printf("%v: CHECKSUM MISMATCH!\n\tComputed: %v\n\tExpected: %v\n", currentJob.path, currentHash, checksumValue)
}
SetCheckedTimeXattr(currentJob.path, time.Now().Unix())
duration := time.Since(time_start)
currentJob.duration += duration
Trace.Printf("%v: End Processing took %v\n", currentJob.path, duration)
Info.Printf("%v: Finished in %v @ %v.\n", currentJob.path, currentJob.duration, currentJob.dataRate)
return nil
}()
if err != nil {
Error.Printf("%v: End Processing: %v\n", currentJob.path, err)
}
}
}