-
Notifications
You must be signed in to change notification settings - Fork 19
/
update.go
55 lines (51 loc) · 1.17 KB
/
update.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
package scanner
import (
"time"
"github.com/Symantec/Dominator/lib/objectcache"
)
func (fsh *FileSystemHistory) update(newFS *FileSystem) {
now := time.Now()
if newFS == nil {
fsh.timeOfLastScan = now
return
}
same := false
if fsh.fileSystem != nil {
same = CompareFileSystems(fsh.fileSystem, newFS, nil)
}
fsh.rwMutex.Lock()
defer fsh.rwMutex.Unlock()
fsh.durationOfLastScan = now.Sub(fsh.timeOfLastScan)
scanTimeDistribution.Add(fsh.durationOfLastScan)
fsh.scanCount++
fsh.timeOfLastScan = now
if fsh.fileSystem == nil {
fsh.fileSystem = newFS
fsh.generationCount = 1
fsh.timeOfLastChange = fsh.timeOfLastScan
} else {
if !same {
fsh.generationCount++
fsh.fileSystem = newFS
fsh.timeOfLastChange = fsh.timeOfLastScan
}
}
}
func (fsh *FileSystemHistory) updateObjectCacheOnly() error {
if fsh.fileSystem == nil {
return nil
}
oldObjectCache := fsh.fileSystem.ObjectCache
if err := fsh.fileSystem.ScanObjectCache(); err != nil {
return err
}
same := objectcache.CompareObjects(oldObjectCache,
fsh.fileSystem.ObjectCache, nil)
fsh.rwMutex.Lock()
defer fsh.rwMutex.Unlock()
fsh.scanCount++
if !same {
fsh.generationCount++
}
return nil
}