summary

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxPathLen = 4096
)

Variables

This section is empty.

Functions

func GIDToName

func GIDToName(gid uint32, cache map[uint32]string) string

GIDToName converts gid to group name, using the given cache to avoid lookups.

func UIDToName

func UIDToName(uid uint32, cache map[uint32]string) string

UIDToName converts uid to username, using the given cache to avoid lookups.

Types

type DirectoryPath

type DirectoryPath struct {
	Name   string
	Depth  int
	Parent *DirectoryPath
}

DirectoryPath represents a linked-list of path parts, which the next element being the parent directory.

func (*DirectoryPath) AppendTo

func (d *DirectoryPath) AppendTo(p []byte) []byte

AppendTo will append the full path to the given byte slice, returning the slice.

func (*DirectoryPath) Len

func (d *DirectoryPath) Len() int

Len returns the length of the path.

func (*DirectoryPath) Less

func (d *DirectoryPath) Less(e *DirectoryPath) bool

Less implements the sort.Interface interface.

type FileInfo

type FileInfo struct {
	Path      *DirectoryPath
	Name      []byte
	Size      int64
	UID       uint32
	GID       uint32
	MTime     int64
	ATime     int64
	CTime     int64
	Inode     int64
	EntryType byte
}

FileInfo represents the parsed information about a file or directory.

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

IsDir returns true if the FileInfo represents a directory.

type GroupUserID

type GroupUserID uint64

GroupUserID is a combined GID and UID.

func NewGroupUserID

func NewGroupUserID(gid, uid uint32) GroupUserID

NewGroupUserID create a new GroupUserID.

func (GroupUserID) GID

func (g GroupUserID) GID() uint32

GID returns the GID.

func (GroupUserID) UID

func (g GroupUserID) UID() uint32

UID returns the UID.

type Operation

type Operation interface {
	// Add is called once for the containing directory and for each of its
	// descendents during a Summariser.Summarise() call.
	Add(info *FileInfo) error

	// Output is called when we return to the parent directory during a
	// Summariser.Summarise() call, having processed all descendent entries.
	//
	// For an Operation working on a directory, this method must also do any
	// necessary reset of the instance of the type before returning.
	Output() error
}

Operation is a type that receives file information either for a directory, and it's descendants, or for an entire tree.

type OperationGenerator

type OperationGenerator func() Operation

OperationGenerator is used to generate an Operation for a Summariser.Summarise() run.

Will be called a single time as a Global Operator and multiple times as a Directory Operator.

type Summariser

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

Summariser provides methods to register Operators that act on FileInfo entries in a tree.

func NewSummariser

func NewSummariser(p *stats.StatsParser) *Summariser

NewSummariser returns a new Summariser that will read from the given stats.StatsParser.

func (*Summariser) AddDirectoryOperation

func (s *Summariser) AddDirectoryOperation(op OperationGenerator)

AddDirectoryOperation will add an operation that will be created for each directory, receiving information for all of its descendants.

func (*Summariser) AddGlobalOperation

func (s *Summariser) AddGlobalOperation(op OperationGenerator)

AddGlobalOperation will add an operation that will be passed information for every file parsed.

func (*Summariser) Summarise

func (s *Summariser) Summarise() error

Summarise will read from the stats.StatsParser and pass that information to the Operations it has been given.

type Summary

type Summary struct {
	Count int64
	Size  int64
}

Summary holds count and size and lets you accumulate count and size as you add more things with a size.

func (*Summary) Add

func (s *Summary) Add(size int64)

Add will increment our count and add the given size to our size.

type SummaryWithTimes

type SummaryWithTimes struct {
	Summary
	Atime int64 // seconds since Unix epoch
	Mtime int64 // seconds since Unix epoch
}

SummaryWithTimes is like summary, but also holds the reference time, oldest atime, newest mtime add()ed.

func (*SummaryWithTimes) Add

func (s *SummaryWithTimes) Add(size int64, atime int64, mtime int64)

Add will increment our count and add the given size to our size. It also stores the given atime if it is older than our current one, and the given mtime if it is newer than our current one.

func (*SummaryWithTimes) AddSummary

func (s *SummaryWithTimes) AddSummary(t *SummaryWithTimes)

AddSummary add the data in the passed SummaryWithTimes to the existing SummaryWithTimes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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