Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileStats ¶
type FileStats struct { QuotedPath string Size int64 UID uint32 GID uint32 Atim int64 Mtim int64 Ctim int64 Type FileType Ino uint64 Nlink uint64 Dev uint64 }
FileStats contains all the file stats needed by wrstat, interpreted in our custom way.
type Operation ¶
Operation is a callback that once added to a Paths will be called on each path encountered. It receives the absolute path to the filesystem entry, and the FileInfo returned by Statter.Lstat() on that path.
func FileOperation ¶
FileOperation returns an Operation that can be used with Paths that calls File() on each path the Operation receives and outputs the ToString() value to the given output file.
type Paths ¶
Paths lets you get stats and carry out operations on those stats for many file paths.
func NewPaths ¶
func NewPaths(statter Statter, pathsConfig PathsConfig) *Paths
NewPaths returns a Paths that will use the given Statter to do the Lstat calls and log issues to any configured logger. If you configure a reportFrequency greater than 0, then timings for the lstats and your operations will also be logged. You can also configure a MaxTime that a Scan() can run for before it fails.
func (*Paths) AddOperation ¶
AddOperation adds the given Operation callback so that when you Scan(), your callback will be called for each path scanned. You give the operation a name so that timings can be reported for each operation.
You can't use the name "lstat", since that is used for reporting the Lstat timings.
func (*Paths) Scan ¶
Scan scans through the given reader which should consist of quoted absolute file path per line. It calls our Statter.Lstat() on each, and passes the absolute path and FileInfo to any Operation callbacks you've added. Errors from the Statter are normally ignored, with the exeption of StatterWithTimeout's failure due to too many consecutive timeouts in a row.
Operations are run concurrently (so should not do something like write to the same file) and their errors logged, but otherwise ignored.
We wait for all operations to complete before they are all called again, so it is safe to do something like write stat details to a file.
If a MaxTime has been configured, Scan() will stop and return an error as soon as that amount of time has passed.
type PathsConfig ¶ added in v5.2.2
type Statter ¶
type Statter interface { // Lstat calls os.Lstat() on the given path, returning the FileInfo. Lstat(path string) (info fs.FileInfo, err error) }
Statter is something you use to get stats of files on disk.
type StatterWithTimeout ¶
type StatterWithTimeout struct {
// contains filtered or unexported fields
}
StatterWithTimeout is a Statter implementation. NB: this is NOT thread safe; you should only call Lstat() one at a time.
func WithTimeout ¶
func WithTimeout(timeout time.Duration, maxAttempts, maxFailureCount int, logger log15.Logger) *StatterWithTimeout
WithTimeout returns a Statter with the given timeout, maxAttempts and maxFailureCount configured. Timeouts are logged with the given logger.
Timeouts on single files do not result in an error, but timeouts of maxFailureCount consecutive files does.
func (*StatterWithTimeout) Lstat ¶
func (s *StatterWithTimeout) Lstat(path string) (info fs.FileInfo, err error)
Lstat calls os.Lstat() on the given path, but times it out after our configured timeout, retrying until we've hit our maxAttempts. NB: this is NOT thread safe, don't call this concurrently.
func (*StatterWithTimeout) SetLstat ¶ added in v5.2.2
func (s *StatterWithTimeout) SetLstat(lstat LstatFunc)
SetLstat can be used when testing when you need to mock actual Lstat calls. The lstat defaults to os.Lstat.