-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathbackup_file_description.go
50 lines (42 loc) · 1.33 KB
/
backup_file_description.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
package internal
import (
"sort"
"time"
)
const MaxCorruptBlocksInFileDesc int = 10
type BackupFileDescription struct {
IsIncremented bool // should never be both incremented and Skipped
IsSkipped bool
MTime time.Time
CorruptBlocks *CorruptBlocksInfo `json:",omitempty"`
UpdatesCount uint64
}
func NewBackupFileDescription(isIncremented, isSkipped bool, modTime time.Time) *BackupFileDescription {
return &BackupFileDescription{isIncremented, isSkipped, modTime, nil, 0}
}
type CorruptBlocksInfo struct {
CorruptBlocksCount int
SomeCorruptBlocks []uint32
}
func (desc *BackupFileDescription) SetCorruptBlocks(corruptBlockNumbers []uint32, storeAllBlocks bool) {
if len(corruptBlockNumbers) == 0 {
return
}
sort.Slice(corruptBlockNumbers, func(i, j int) bool {
return corruptBlockNumbers[i] < corruptBlockNumbers[j]
})
corruptBlocksCount := len(corruptBlockNumbers)
// write no more than MaxCorruptBlocksInFileDesc
someCorruptBlocks := make([]uint32, 0)
for idx, blockNo := range corruptBlockNumbers {
if !storeAllBlocks && idx >= MaxCorruptBlocksInFileDesc {
break
}
someCorruptBlocks = append(someCorruptBlocks, blockNo)
}
desc.CorruptBlocks = &CorruptBlocksInfo{
CorruptBlocksCount: corruptBlocksCount,
SomeCorruptBlocks: someCorruptBlocks,
}
}
type BackupFileList map[string]BackupFileDescription