github.com/Cloud-Foundations/Dominator@v0.3.4/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 openingHasher interface {
    19  	Hasher
    20  	OpenAndHash(inode *filesystem.RegularInode, pathName string) (bool, error)
    21  }
    22  
    23  type simpleHasher bool // If true, ignore short reads.
    24  
    25  type cpuLimitedHasher struct {
    26  	limiter *cpulimiter.CpuLimiter
    27  	hasher  Hasher
    28  }
    29  
    30  type FileSystem struct {
    31  	rootDirectoryName       string
    32  	fsScanContext           *fsrateio.ReaderContext
    33  	scanFilter              *filter.Filter
    34  	checkScanDisableRequest func() bool
    35  	hasher                  Hasher
    36  	dev                     uint64
    37  	inodeNumber             uint64
    38  	filesystem.FileSystem
    39  }
    40  
    41  func MakeRegularInode(stat *wsyscall.Stat_t) *filesystem.RegularInode {
    42  	return makeRegularInode(stat)
    43  }
    44  
    45  func MakeSymlinkInode(stat *wsyscall.Stat_t) *filesystem.SymlinkInode {
    46  	return makeSymlinkInode(stat)
    47  }
    48  
    49  func MakeSpecialInode(stat *wsyscall.Stat_t) *filesystem.SpecialInode {
    50  	return makeSpecialInode(stat)
    51  }
    52  
    53  func ScanFileSystem(rootDirectoryName string,
    54  	fsScanContext *fsrateio.ReaderContext, scanFilter *filter.Filter,
    55  	checkScanDisableRequest func() bool, hasher Hasher, oldFS *FileSystem) (
    56  	*FileSystem, error) {
    57  	return scanFileSystem(rootDirectoryName, fsScanContext, scanFilter,
    58  		checkScanDisableRequest, hasher, oldFS)
    59  }
    60  
    61  func (fs *FileSystem) GetObject(hashVal hash.Hash) (
    62  	uint64, io.ReadCloser, error) {
    63  	return fs.getObject(hashVal)
    64  }
    65  
    66  func GetSimpleHasher(ignoreShortReads bool) Hasher {
    67  	return simpleHasher(ignoreShortReads)
    68  }
    69  
    70  func (h simpleHasher) Hash(reader io.Reader, length uint64) (hash.Hash, error) {
    71  	return h.hash(reader, length)
    72  }
    73  
    74  func NewCpuLimitedHasher(cpuLimiter *cpulimiter.CpuLimiter,
    75  	hasher Hasher) cpuLimitedHasher {
    76  	return cpuLimitedHasher{cpuLimiter, hasher}
    77  }
    78  
    79  func (h cpuLimitedHasher) Hash(reader io.Reader, length uint64) (
    80  	hash.Hash, error) {
    81  	return h.hash(reader, length)
    82  }