/
api.go
82 lines (66 loc) · 2.19 KB
/
api.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
78
79
80
81
82
package scanner
import (
"io"
"github.com/Cloud-Foundations/Dominator/lib/cpulimiter"
"github.com/Cloud-Foundations/Dominator/lib/filesystem"
"github.com/Cloud-Foundations/Dominator/lib/filter"
"github.com/Cloud-Foundations/Dominator/lib/fsrateio"
"github.com/Cloud-Foundations/Dominator/lib/hash"
"github.com/Cloud-Foundations/Dominator/lib/wsyscall"
)
type Hasher interface {
Hash(reader io.Reader, length uint64) (hash.Hash, error)
}
type openingHasher interface {
Hasher
OpenAndHash(inode *filesystem.RegularInode, pathName string) (bool, error)
}
type simpleHasher bool // If true, ignore short reads.
type cpuLimitedHasher struct {
limiter *cpulimiter.CpuLimiter
hasher Hasher
}
type FileSystem struct {
rootDirectoryName string
fsScanContext *fsrateio.ReaderContext
scanFilter *filter.Filter
checkScanDisableRequest func() bool
hasher Hasher
dev uint64
inodeNumber uint64
filesystem.FileSystem
}
func MakeRegularInode(stat *wsyscall.Stat_t) *filesystem.RegularInode {
return makeRegularInode(stat)
}
func MakeSymlinkInode(stat *wsyscall.Stat_t) *filesystem.SymlinkInode {
return makeSymlinkInode(stat)
}
func MakeSpecialInode(stat *wsyscall.Stat_t) *filesystem.SpecialInode {
return makeSpecialInode(stat)
}
func ScanFileSystem(rootDirectoryName string,
fsScanContext *fsrateio.ReaderContext, scanFilter *filter.Filter,
checkScanDisableRequest func() bool, hasher Hasher, oldFS *FileSystem) (
*FileSystem, error) {
return scanFileSystem(rootDirectoryName, fsScanContext, scanFilter,
checkScanDisableRequest, hasher, oldFS)
}
func (fs *FileSystem) GetObject(hashVal hash.Hash) (
uint64, io.ReadCloser, error) {
return fs.getObject(hashVal)
}
func GetSimpleHasher(ignoreShortReads bool) Hasher {
return simpleHasher(ignoreShortReads)
}
func (h simpleHasher) Hash(reader io.Reader, length uint64) (hash.Hash, error) {
return h.hash(reader, length)
}
func NewCpuLimitedHasher(cpuLimiter *cpulimiter.CpuLimiter,
hasher Hasher) cpuLimitedHasher {
return cpuLimitedHasher{cpuLimiter, hasher}
}
func (h cpuLimitedHasher) Hash(reader io.Reader, length uint64) (
hash.Hash, error) {
return h.hash(reader, length)
}