Documentation ¶
Index ¶
- Variables
- type AttrHandler
- type AttrIssue
- type AttrOutcome
- type Dir
- type Examination
- type ExaminationFunc
- type File
- type FileFunc
- type FileIter
- type FileTimeType
- type Issue
- type IssueHandler
- type JobStats
- type NameHandler
- type NameIssue
- type NameOutcome
- type Operation
- func (op *Operation) Close() error
- func (op *Operation) DryRun() bool
- func (op *Operation) FileChanged() (bool, error)
- func (op *Operation) Index() int
- func (op *Operation) OriginalModTime() time.Time
- func (op *Operation) OriginalMode() fs.FileMode
- func (op *Operation) OriginalName() string
- func (op *Operation) OriginalPath() string
- func (op *Operation) OriginalSize() int64
- func (op *Operation) Root() Dir
- func (op *Operation) WithFile(fn FileFunc) error
- func (op *Operation) WithFileExclusive(fn FileFunc) error
- type OperationFunc
- type Outcome
- type Pattern
- type ScanIssue
- type Scanner
- type Summary
- type TimeHandler
- type TimeIssue
- type TimeOutcome
Constants ¶
This section is empty.
Variables ¶
var ErrDryRun = errors.New("dry run")
ErrDryRun is reported as the outcome for fixes when an operation was created as a dry run.
var ErrFileChanged = errors.New("the file has changed since the file was examined")
ErrFileChanged is returned by some issue handlers when they detect that a file changed between the time it was examined and the time that a fix was requested.
var ErrScanCancelled = errors.New("the scan has been cancelled")
ErrScanCancelled is reported by FileIter.Err() if it's been cancelled.
Functions ¶
This section is empty.
Types ¶
type AttrHandler ¶
AttrHandler handles file attribute issues.
func (AttrHandler) Examine ¶
func (h AttrHandler) Examine(ctx context.Context, exam *Examination) []Issue
Examine checks the file under examination for issues. It returns nil if no issues are identified.
type AttrIssue ¶
type AttrIssue struct { Original fileattr.Value Matched fileattr.Value AttrHandler }
NameIssue describes a file name issue.
func (AttrIssue) Description ¶
Description returns a description of the issue. It may return an empty string if the information provided by the summary is sufficient.
func (AttrIssue) FileOpenFlags ¶
FileOpenFlags returns the set of file permission flags required to fix the issue.
func (AttrIssue) Handler ¶
func (issue AttrIssue) Handler() IssueHandler
Handler returns the Handler that's responsible for handling the name issue.
func (AttrIssue) Resolution ¶
Resolution returns a string describing a proposed resolution to the issue.
type AttrOutcome ¶
type AttrOutcome struct { OldAttributes fileattr.Value NewAttributes fileattr.Value // contains filtered or unexported fields }
AttrOutcome records the outcome of an attempted fix for a file name issue.
func (AttrOutcome) Err ¶
func (outcome AttrOutcome) Err() error
Err returns an error if one was encountered during the operation.
func (AttrOutcome) Issue ¶
func (outcome AttrOutcome) Issue() Issue
Issue returns the issue this outcome pertains to.
func (AttrOutcome) String ¶
func (outcome AttrOutcome) String() string
String returns a string representation of the issue.
type Dir ¶
type Dir string
Dir is a file directory path accessible via operating system API acalls.
type Examination ¶
type Examination struct {
// contains filtered or unexported fields
}
Operation is an operation on a file that has been scanned.
func (*Examination) FileInfo ¶
func (op *Examination) FileInfo() fs.FileInfo
Index returns the index of the file when it was scanned.
func (*Examination) Index ¶
func (op *Examination) Index() int
Index returns the index of the file when it was scanned.
func (*Examination) Path ¶
func (op *Examination) Path() string
Path returns the path of the file within its file system.
type ExaminationFunc ¶
type ExaminationFunc func(*Examination) error
ExaminationFunc is a function that runs within the context of an examination.
type File ¶
type File struct { // Scanned file location Root Dir Path string Index int Skipped bool // FileInfo values collected during a scan (may be empty) Name string Size int64 Mode fs.FileMode ModTime time.Time Issues []Issue }
File describes a file that has been scanned.
func (File) Description ¶
Description returns a multiline string of the file's issues. It returns an empty string if the file has no issue.
func (File) DryOperation ¶
func (f File) DryOperation(fn OperationFunc) error
DryOperation executes an operation for the file as a dry run.
func (File) Operation ¶
func (f File) Operation(fn OperationFunc) error
Operation executes an operation for the file.
type FileIter ¶
type FileIter struct {
// contains filtered or unexported fields
}
FileIter is a file iterator returned by a Scanner. It's used to step through the results of a Scanner as they're produced.
func ScanDir ¶
func ScanDir(ctx context.Context, root Dir, handlers ...IssueHandler) *FileIter
ScanDir scans the given file system directory for issues.
func (*FileIter) Err ¶
Err returns a non-nil error if the iterator's job encountered an error and stopped. It should be called after Scan() returns false. It returns nil if the job completed successfully.
func (*FileIter) File ¶
File returns the most recently matched file. It is updated each time Scan() returns true. Scan() must be called at least once before calling this funcion.
type FileTimeType ¶
type FileTimeType int
FileTimeType identifies a type of file timestamp.
const ( FileTimeCreation FileTimeType = iota FileTimeAccess FileTimeLastWrite FileTimeChange )
Timestamp types.
func (FileTimeType) String ¶
func (t FileTimeType) String() string
String returns a string representation of the timestamp type.
type Issue ¶
type Issue interface { // Handler returns the Handler that's responsible for handling the issue. Handler() IssueHandler // Summary returns a short summary of the issue. Summary() string // Description returns a description of the issue. It may return an empty // string if the information provided by the summary is sufficient. Description() string // Resolution returns a string describing the fix. It returns an empty // string if no resolution is possible. Resolution() string // FileOpenFlags returns the set of file permission flags required to fix // the issue. FileOpenFlags() int // Fix attempts to fix the issue. Fix(context.Context, *Operation) Outcome }
Issue describes a problem with a file.
type IssueHandler ¶
type IssueHandler interface { // Name returns the name of the handler. Name() string // Examine checks the file under examination for issues. It returns nil if no // issues are identified. Examine(context.Context, *Examination) []Issue }
IssueHandler handles file issues of a particular type.
type JobStats ¶
type JobStats struct { // Skipped is the number of files not scanned due to filters. Skipped int // Scanned is the number of files scanned. Scanned int // Healthy is the number of scanned files that had no issues. Healthy int // Unhealthy is the number of scanned files that had at least one issue. Unhealthy int // Issues is the total number of issues detected in scanned files. Issues int }
JobStats report scanning tallies during and at the completion of scanning.
type NameHandler ¶
type NameHandler struct {
TrimSpace bool
}
NameHandler handles file name issues.
func (NameHandler) Examine ¶
func (h NameHandler) Examine(ctx context.Context, exam *Examination) []Issue
Examine checks the file under examination for issues. It returns nil if no issues are identified.
type NameIssue ¶
type NameIssue struct { OriginalName string NewName string NameHandler }
NameIssue describes a file name issue.
func (NameIssue) Description ¶
Description returns a description of the issue. It may return an empty string if the information provided by the summary is sufficient.
func (NameIssue) FileOpenFlags ¶
FileOpenFlags returns the set of file permission flags required to fix the issue.
func (NameIssue) Handler ¶
func (issue NameIssue) Handler() IssueHandler
Handler returns the Handler that's responsible for handling the name issue.
func (NameIssue) Resolution ¶
Resolution returns a string describing a proposed resolution to the issue.
type NameOutcome ¶
type NameOutcome struct { OldFilePath string NewFilePath string // contains filtered or unexported fields }
NameOutcome records the outcome of an attempted fix for a file name issue.
func (NameOutcome) Err ¶
func (outcome NameOutcome) Err() error
Err returns an error if one was encountered during the operation.
func (NameOutcome) Issue ¶
func (outcome NameOutcome) Issue() Issue
Issue returns the issue this outcome pertains to.
func (NameOutcome) String ¶
func (outcome NameOutcome) String() string
String returns a string representation of the issue.
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation is an operation on a file that has been scanned.
func (*Operation) FileChanged ¶
FileChanged reports whether the file's basic attributes were changed between the time it was scanned and the first time this function is called on the operation.
func (*Operation) OriginalModTime ¶
OriginalModTime returns the modification time of the file at the time it was examined.
func (*Operation) OriginalMode ¶
OriginalMode returns the mode of the file at the time it was examined.
func (*Operation) OriginalName ¶
OriginalName returns the name of the file when it was examined.
func (*Operation) OriginalPath ¶
OriginalPath returns the path of the file within its file system.
func (*Operation) OriginalSize ¶
OriginalSize returns the size of the file at the time it was examined.
func (*Operation) WithFile ¶
WithFile opens the operation's file and invokes the given function on it.
If the file cannot be opened, an error is returned. Otherwise, the result of fn() is returned.
If called more than once, the same fs.File will be returned to each call. Callers should not use this function to read from or write to the file, because the file's position will not be reset between calls.
func (*Operation) WithFileExclusive ¶
WithFileExclusive opens the operation's file and invokes the given function on it.
If the file cannot be opened, an error is returned. Otherwise, the result of fn() is returned.
A unique fs.File will be returned for each call. It is safe to read from and write to the file.
type OperationFunc ¶
OperationFunc is a function that runs within the context of an operation.
type Pattern ¶
Pattern is a file matching pattern based on regular expressions.
func (*Pattern) UnmarshalText ¶
UnmarshalText unmarshals the given text as a pattern in p.
type ScanIssue ¶
type ScanIssue struct {
Err error
}
ScanIssue describes an issue encounterd by a scanner.
func (ScanIssue) Description ¶
Description returns a description of the issue. It may return an empty string if the information provided by the summary is sufficient.
func (ScanIssue) FileOpenFlags ¶
FileOpenFlags returns the set of file permission flags required to fix the issue.
func (ScanIssue) Handler ¶
func (issue ScanIssue) Handler() IssueHandler
Handler returns the Handler that's responsible for handling the issue.
func (ScanIssue) Resolution ¶
Resolution returns a string describing the fix. It returns an empty string if no resolution is possible.
type Scanner ¶
type Scanner struct { // Handlers examine each file passing through the scanner's filters and // determine whether they have issues. They determine what constitutes an "issue". Handlers []IssueHandler // Include is a filter that limits the number of files scanned. If // provided, only files with names matching at least one pattern will // be scanned. Include []Pattern // Exclude is a filter that limits the number of files scanned. If // provided, only files with names that don't match any of its patterns // will be scanned. Exclude []Pattern // SendSkipped requests that skipped files, those that don't pass the // inclusion and exclusion filters, be sent to the iterator. SendSkipped bool // SendHealthy requests that healthy files, those without any issues, be // sent to the iterator. SendHealthy bool }
Scanner scans a set of files for issues identified by its issue handlers.
type TimeHandler ¶
type TimeHandler struct { // Min is the minimum timestamp permitted. Optional. Min time.Time // Max is the maximum timestamp permitted. Optional. Max time.Time // Reference is used to compensate for the passage of time during // long-running operations. Optional. // // When specified, the current time will be compared to the reference // time, and the difference will be added to Min and Max. Reference time.Time // Lenience is used to compensate for inaccurate and unsynchronized. // clocks. Optional. // // Timestamps that are close to Min or Max will be accepted if the // delta is less than lenience. Lenience time.Duration }
TimeHandler handles file timestamp issues.
func (TimeHandler) Examine ¶
func (h TimeHandler) Examine(ctx context.Context, exam *Examination) []Issue
Examine checks the file under examination for issues. It returns nil if no issues are identified.
type TimeIssue ¶
type TimeIssue struct { Type FileTimeType Time time.Time Fallback time.Time TimeHandler }
TimeIssue describes a file modification time issue.
func (TimeIssue) Description ¶
Description returns a description of the issue. It may return an empty string if the information provided by the summary is sufficient.
func (TimeIssue) FileOpenFlags ¶
FileOpenFlags returns the set of file permission flags required to fix the issue.
func (TimeIssue) Handler ¶
func (issue TimeIssue) Handler() IssueHandler
Handler returns the Handler that's responsible for handling the name issue.
func (TimeIssue) Resolution ¶
Resolution returns a string describing a proposed resolution to the issue.
type TimeOutcome ¶
type TimeOutcome struct { OldTime time.Time NewTime time.Time // contains filtered or unexported fields }
TimeOutcome records the outcome of an attempted fix for a file name issue.
func (TimeOutcome) Err ¶
func (outcome TimeOutcome) Err() error
Err returns an error if one was encountered during the operation.
func (TimeOutcome) Issue ¶
func (outcome TimeOutcome) Issue() Issue
Issue returns the issue this outcome pertains to.
func (TimeOutcome) String ¶
func (outcome TimeOutcome) String() string
String returns a string representation of the issue.