github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/filesystem/scanner/api.go (about)

     1  package scanner
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/cpulimiter"
     7  	"github.com/Cloud-Foundations/Dominator/lib/filesystem"
     8  	"github.com/Cloud-Foundations/Dominator/lib/filter"
     9  	"github.com/Cloud-Foundations/Dominator/lib/fsrateio"
    10  	"github.com/Cloud-Foundations/Dominator/lib/hash"
    11  	"github.com/Cloud-Foundations/Dominator/lib/wsyscall"
    12  )
    13  
    14  type Hasher interface {
    15  	Hash(reader io.Reader, length uint64) (hash.Hash, error)
    16  }
    17  
    18  type simpleHasher bool // If true, ignore short reads.
    19  
    20  type cpuLimitedHasher struct {
    21  	limiter *cpulimiter.CpuLimiter
    22  	hasher  Hasher
    23  }
    24  
    25  type FileSystem struct {
    26  	rootDirectoryName       string
    27  	fsScanContext           *fsrateio.ReaderContext
    28  	scanFilter              *filter.Filter
    29  	checkScanDisableRequest func() bool
    30  	hasher                  Hasher
    31  	dev                     uint64
    32  	inodeNumber             uint64
    33  	filesystem.FileSystem
    34  }
    35  
    36  func MakeRegularInode(stat *wsyscall.Stat_t) *filesystem.RegularInode {
    37  	return makeRegularInode(stat)
    38  }
    39  
    40  func MakeSymlinkInode(stat *wsyscall.Stat_t) *filesystem.SymlinkInode {
    41  	return makeSymlinkInode(stat)
    42  }
    43  
    44  func MakeSpecialInode(stat *wsyscall.Stat_t) *filesystem.SpecialInode {
    45  	return makeSpecialInode(stat)
    46  }
    47  
    48  func ScanFileSystem(rootDirectoryName string,
    49  	fsScanContext *fsrateio.ReaderContext, scanFilter *filter.Filter,
    50  	checkScanDisableRequest func() bool, hasher Hasher, oldFS *FileSystem) (
    51  	*FileSystem, error) {
    52  	return scanFileSystem(rootDirectoryName, fsScanContext, scanFilter,
    53  		checkScanDisableRequest, hasher, oldFS)
    54  }
    55  
    56  func (fs *FileSystem) GetObject(hashVal hash.Hash) (
    57  	uint64, io.ReadCloser, error) {
    58  	return fs.getObject(hashVal)
    59  }
    60  
    61  func GetSimpleHasher(ignoreShortReads bool) Hasher {
    62  	return simpleHasher(ignoreShortReads)
    63  }
    64  
    65  func (h simpleHasher) Hash(reader io.Reader, length uint64) (hash.Hash, error) {
    66  	return h.hash(reader, length)
    67  }
    68  
    69  func NewCpuLimitedHasher(cpuLimiter *cpulimiter.CpuLimiter,
    70  	hasher Hasher) cpuLimitedHasher {
    71  	return cpuLimitedHasher{cpuLimiter, hasher}
    72  }
    73  
    74  func (h cpuLimitedHasher) Hash(reader io.Reader, length uint64) (
    75  	hash.Hash, error) {
    76  	return h.hash(reader, length)
    77  }