Documentation ¶
Index ¶
- Variables
- func ChecksumFiles(groups ...[]File)
- func ChecksumFilesFS(fs fs.FileSystem, groups ...[]File)
- func CleanPath(path string) string
- func MakeDir(path string) error
- func MakeDirFS(fs fs.FileSystem, path string) error
- func ReadFile(filename string) ([]byte, error)
- func ReadFileFS(fs fs.FileSystem, filename string) ([]byte, error)
- func WriteFile(filename string, data []byte) error
- func WriteFileFS(fs fs.FileSystem, filename string, data []byte) error
- type ByPath
- type BySize
- type File
- type PathScanner
Constants ¶
This section is empty.
Variables ¶
var DefaultFileSystem = fs.OS
The DefaultFileSystem represents the actual OS filesystem and will read files and data from disk as normal. Other FileSystems are used when testing to allow for easy injection of faults.
Functions ¶
func ChecksumFiles ¶
func ChecksumFiles(groups ...[]File)
ChecksumFiles scans file contents on the DefaultFileSystem.
func ChecksumFilesFS ¶
func ChecksumFilesFS(fs fs.FileSystem, groups ...[]File)
ChecksumFilesFS scans the contents of a list of files, calculating their SHA1 checksums and populating the File details.
func CleanPath ¶
CleanPath resolves the shortest path name equivalent, also replacing any occurrences of the ~/ prefix with the actual home directory path.
func MakeDir ¶
MakeDir creates a directory path, along with any necessary parents, using the default permissions of 0755 (drwxr-xr-x).
func ReadFileFS ¶
func ReadFileFS(fs fs.FileSystem, filename string) ([]byte, error)
func WriteFile ¶
WriteFile writes data to a file. If the file doesn't exist, it is created with default permissions of 0644 (-rw-r--r--), otherwise it is truncated.
func WriteFileFS ¶
func WriteFileFS(fs fs.FileSystem, filename string, data []byte) error
Types ¶
type ByPath ¶
type ByPath []File
ByPath implements sort.Interface for sorting a list of files by path.
type BySize ¶
type BySize []File
BySize implements sort.Interface for sorting a list of files by size.
type File ¶
type File struct { Root string // Parent path of the file. Name string // Base name of the file. Size int64 // Length in bytes for regular files. Mode os.FileMode // File mode and permission bits. ModTime time.Time // Last modification time. UID int // User identifier of owner. GID int // Group identifier of owner. SHA1 [sha1.Size]byte // Checksum of the file contents. }
func ScanFileFS ¶
func ScanFileFS(fs fs.FileSystem, path string) File
func (File) HasChecksum ¶
HasChecksum checks if the SHA1 for this file has been populated.
type PathScanner ¶
type PathScanner struct {
// contains filtered or unexported fields
}
PathScanner scans multiple file paths in parallel.
func NewScannerFS ¶
func NewScannerFS(fs fs.FileSystem) *PathScanner
func (*PathScanner) ExcludePath ¶
func (s *PathScanner) ExcludePath(path string) *PathScanner
Exclude a path from scanning. This supersedes the included paths.
func (*PathScanner) IncludePath ¶
func (s *PathScanner) IncludePath(path string) *PathScanner
Include a path to be scanned. Will always resolve paths to an absolute path, based on current working dir.
func (*PathScanner) Scan ¶
func (s *PathScanner) Scan() []File
Scan performs the scan. Comparable speed to a `find ... -mtime 1`, as it does a syscall.ReadDirent as well as syscall.Lstat (and Stat_t) for every file.
func (*PathScanner) ScanRelativeTo ¶
func (s *PathScanner) ScanRelativeTo(root string) []File
ScanRelativeTo performs the scan, changing the root path of scanned files to be relative to some new root.