Documentation
¶
Overview ¶
Package filesearch provides functionality for searching the local filesystem.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindUniqueFiles ¶
func FindUniqueFiles(config FindUniqueFilesConfig) error
FindUniqueFiles searches a given directory for files using the provided config by wrapping filepath.Walk().
The main feature of this function is that it can ignore duplicate files. This behavior can be adjusted as desired in config.
Types ¶
type FindUniqueFilesConfig ¶
type FindUniqueFilesConfig struct {
// TargetDirPath is the directory to search.
TargetDirPath string
// Recursive, when true, will search TargetDirPath recursively.
Recursive bool
// AllowDupes, when true, will not track file hashes and will
// always report files as never being seen.
AllowDupes bool
// HasherFn returns a hash.Hash to use when hashing a file.
//
// sha256.New() is used if nil.
HasherFn func() hash.Hash
// IncludeFileFn is called when a file is encountered during
// the search. If the function returns 'true', the file will
// be included. Otherwise, the file will be ignored.
IncludeFileFn func(fullFilePath string) (shouldInclude bool)
// FoundFileFn is called when IncludeFileFn returns true.
FoundFileFn func(StatefulFileInfo) error
}
FindUniqueFilesConfig configures a FindUniqueFiles function.
func (FindUniqueFilesConfig) Validate ¶
func (o FindUniqueFilesConfig) Validate() error
type StatefulFileInfo ¶
type StatefulFileInfo struct {
// AlreadySeen is true if the file has been encountered before.
//
// This is always false if FindUniqueFilesConfig.AllowDupes is true.
AlreadySeen bool
// FilePath is the absolute file path of the file.
FilePath string
// PreviousFilePath is the file path where the file has been
// previously encountered. If the file has not been previously
// encountered, then this is an empty string.
PreviousFilePath string
// ParentDirPath is the parent directory of the file.
ParentDirPath string
// Hash is the hash string of the file.
//
// This is an empty string if FindUniqueFilesConfig.AllowDupes is true.
Hash string
// Info is the file's os.FileInfo.
Info os.FileInfo
// AbsSearchDirPath is the absolute path of the directory
// that was initially searched.
AbsSearchDirPath string
}
StatefulFileInfo expands on os.FileInfo, including additional information about the state of the file.
Click to show internal directories.
Click to hide internal directories.