file

package
v0.0.0-...-7234002 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func CleanPath(path string) string

CleanPath resolves the shortest path name equivalent, also replacing any occurrences of the ~/ prefix with the actual home directory path.

func MakeDir

func MakeDir(path string) error

MakeDir creates a directory path, along with any necessary parents, using the default permissions of 0755 (drwxr-xr-x).

func MakeDirFS

func MakeDirFS(fs fs.FileSystem, path string) error

func ReadFile

func ReadFile(filename string) ([]byte, error)

ReadFile reads the contents of a file.

func ReadFileFS

func ReadFileFS(fs fs.FileSystem, filename string) ([]byte, error)

func WriteFile

func WriteFile(filename string, data []byte) error

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.

func (ByPath) Len

func (a ByPath) Len() int

func (ByPath) Less

func (a ByPath) Less(i, j int) bool

Sort by root path and then by filename within each root.

func (ByPath) Swap

func (a ByPath) Swap(i, j int)

type BySize

type BySize []File

BySize implements sort.Interface for sorting a list of files by size.

func (BySize) Len

func (a BySize) Len() int

func (BySize) Less

func (a BySize) Less(i, j int) bool

func (BySize) Swap

func (a BySize) Swap(i, j int)

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 ScanFile

func ScanFile(path string) File

ScanFile scans a single file path.

func ScanFileFS

func ScanFileFS(fs fs.FileSystem, path string) File

func (*File) FileInfo

func (f *File) FileInfo() os.FileInfo

func (File) HasChecksum

func (f File) HasChecksum() bool

HasChecksum checks if the SHA1 for this file has been populated.

func (File) IsDir

func (f File) IsDir() bool

IsDir checks if this is a directory.

func (File) IsRegular

func (f File) IsRegular() bool

IsRegular checks if this is a regular file.

func (f File) IsSymlink() bool

IsSymlink checks if this is a symlink.

func (File) Path

func (f File) Path() string

Path returns the full file path (Root+Name).

func (File) String

func (f File) String() string

String representation for nicer logging / console output.

type PathScanner

type PathScanner struct {
	// contains filtered or unexported fields
}

PathScanner scans multiple file paths in parallel.

func NewScanner

func NewScanner() *PathScanner

NewScanner scans paths on the DefaultFileSystem.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL