Documentation ¶
Overview ¶
Package file provides the capability to parse from and write to disk a roster configuration and index file. The roster file is currently implemented in YAML format to minimize file size and also permit user annotation with comments.
Index ¶
- Constants
- Variables
- func Checksum(filePath string) (sum string, err error)
- type Absent
- type Config
- type DirectoryNotFoundError
- type Ignore
- type IgnoreRegexp
- type InvalidPathError
- type Member
- type NotRegularFileError
- type Roster
- func (ros *Roster) Absentees() []string
- func (ros *Roster) Changed(root string, relPath string, info os.FileInfo) (new bool, changed bool, stat Status, err error)
- func (ros *Roster) Expel(filePath string)
- func (ros *Roster) Keep(filePath string, info os.FileInfo) bool
- func (ros *Roster) Status(filePath string) (Status, bool)
- func (ros *Roster) Update(filePath string, stat Status) error
- func (ros *Roster) Write() error
- type Runtime
- type Status
- type Verify
Constants ¶
const ( RuntimeThreadsNoLimit = 0 // number of threads limited to number of CPUs RuntimeDepthNoLimit = 0 // unlimited recursion )
Constants representing special-purpose values for Runtime fields.
const ( StatusNoFsize int64 = -1 StatusPermsMask uint64 = 0x00000000FFFFFFFF StatusNoPerms string = "(none)" StatusNoMtime string = "(none)" StatusNoCheck string = "" )
Constants defining Status field values with special meaning.
Variables ¶
var IgnoreDefault = Ignore{"\\.git", "\\.svn"}
IgnoreDefault defines the default Ignore patterns used when creating a new roster file. The default items are VCS metadata directories.
var Permissions os.FileMode = 0600
Permissions defines the default permissions of roster files written to disk.
Functions ¶
Types ¶
type Absent ¶
Absent stores a record of all files in the roster, which are removed once the file is discovered.
type Config ¶
type Config struct { Rt Runtime `yaml:"runtime"` // various runtime settings Ver Verify `yaml:"verify"` // attributes used to identify changed files Ign Ignore `yaml:"ignore"` // file patterns to exclude from roster index // contains filtered or unexported fields }
Config contains settings for constructing and verifying the roster index.
type DirectoryNotFoundError ¶
type DirectoryNotFoundError string
func (DirectoryNotFoundError) Error ¶
func (e DirectoryNotFoundError) Error() string
Error returns the error message for DirectoryNotFoundError.
type Ignore ¶
type Ignore []string
Ignore stores a list of file patterns to exclude from the roster index.
func (Ignore) Compile ¶
func (i Ignore) Compile() (*IgnoreRegexp, error)
Compile builds a list of regular expressions from a string slice of ignore patterns.
type IgnoreRegexp ¶
IgnoreRegexp stores a list of compiled regular expressions created from a slice of strings of type Ignore.
type InvalidPathError ¶
type InvalidPathError string
func (InvalidPathError) Error ¶
func (e InvalidPathError) Error() string
Error returns the error message for InvalidPathError.
type Member ¶
Member stores the index of all roster members as a mapping from file path to Status struct containing file attributes.
type NotRegularFileError ¶
type NotRegularFileError string
func (NotRegularFileError) Error ¶
func (e NotRegularFileError) Error() string
Error returns the error message for NotRegularFileError.
type Roster ¶
type Roster struct { Cfg Config `yaml:"config"` // roster configuration Mem Member `yaml:"members"` // index of all files // contains filtered or unexported fields }
Roster represents a roster file, containing the index of all member files in a directory tree.
func New ¶
New constructs a new roster file at the given file path, initialized with all default data. The returned file is stored in-memory only. The Write method must be called to write the file to disk.
func Parse ¶
Parse parses the roster configuration and member data from a given roster file into the returned Roster struct, or returns a Roster struct with default configuration and empty member data if the roster file does not exist. Returns a nil Roster and descriptive error if the given path is invalid.
func (*Roster) Absentees ¶
Absentees returns a list of files that remain in the receiver Roster ros's list of missing files.
func (*Roster) Changed ¶
func (ros *Roster) Changed(root string, relPath string, info os.FileInfo) ( new bool, changed bool, stat Status, err error, )
Changed determines if the given file path and os.FileInfo already exists in the roster index, computes the Status struct for the given file, and returns whether it is a new file, whether the Status info has changed, and what the new Status is, along with any error encountered.
func (*Roster) Keep ¶
Keep returns whether or not a file with the given path should be considered candidate for indexing. Directories, files matching an ignore pattern, and the roster index file itself all return false.
func (*Roster) Status ¶
Status checks if the given file path exists in the index and returns its corresponding Status struct and true. If the file path does not exist, it returns the unique NoStatus struct and false.
type Status ¶
type Status struct { Fsize int64 `yaml:"size"` Perms string `yaml:"perm"` Mtime string `yaml:"last"` Check string `yaml:"hash"` }
Status represents all verifiable attributes of an indexed file.
func MakeStatus ¶
MakeStatus constructs a new Status struct. This method does not consider the Verify settings, and it will always analyze all attributes of the given file.
func NoStatus ¶
func NoStatus() Status
NoStatus returns a default Status struct for files that have not been analyzed.