stat

package
v4.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type FileStats

type FileStats struct {
	Base64Path 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.

func File

func File(absPath string, info os.FileInfo) *FileStats

File interprets the given file info to produce a FileStats.

You provide the absolute path to the file so that Base64Path can be calculated correctly (the info only contains the basename).

func (*FileStats) ToString

func (fs *FileStats) ToString() string

ToString produces our special format for describing the stats of a file. It is \n terminated and ready to be written to a file.

type FileType

type FileType string
const (
	FileTypeRegular FileType = "f"
	FileTypeLink    FileType = "l"
	FileTypeDir     FileType = "d"
	FileTypeSocket  FileType = "s"
	FileTypeBlock   FileType = "b"
	FileTypeChar    FileType = "c"
	FileTypeFIFO    FileType = "F"
	FileTypeUnknown FileType = "X"
)

type Operation

type Operation func(absPath string, info fs.FileInfo) error

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

func FileOperation(output *os.File) Operation

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

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

Paths lets you get stats and carry out operations on those stats for many file paths.

func NewPaths

func NewPaths(statter Statter, logger log15.Logger, reportFrequency time.Duration) *Paths

NewPaths returns a Paths that will use the given Statter to do the Lstat calls and log issues to the logger. If you supply a reportFrequency greater than 0, then timings for the lstats and your operations will also be logged.

func (*Paths) AddOperation

func (p *Paths) AddOperation(name string, op Operation) error

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

func (p *Paths) Scan(paths io.Reader) error

Scan scans through the given reader which should consist of an 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.

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.

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 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 int, logger log15.Logger) *StatterWithTimeout

WithTimeout returns a Statter with the given timeout and maxAttempts configured. Timeouts are logged with the given logger.

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.

Jump to

Keyboard shortcuts

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