structure

package
v0.5.0-nightly Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxTopEntries = 16

Variables

View Source
var TopEntriesInstance = NewTopEntries(DefaultMaxTopEntries)

Functions

func DiffStats added in v0.3.0

func DiffStats(entries []*Entry) (uint64, uint64, int64)

Types

type Decoder added in v0.3.0

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

func NewDecoder added in v0.3.0

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode added in v0.3.0

func (d *Decoder) Decode(v any) error

type Diff added in v0.3.0

type Diff struct {
	Same    []EntryPair
	Added   []*Entry
	Removed []*Entry
}

func (*Diff) Empty added in v0.4.1

func (d *Diff) Empty() bool

func (*Diff) Sort added in v0.3.0

func (d *Diff) Sort() *Diff

type Encoder added in v0.3.0

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

func NewEncoder added in v0.3.0

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode added in v0.3.0

func (e *Encoder) Encode(v any) error

type Entry

type Entry struct {
	// Path contains the full path to the file or directory represented as an
	// instance of the entry.
	Path string

	// Child contains a list of all child instances including both files and
	// directories. If the current Entry instance represents a file, this
	// property will always be nil.
	Child []*Entry

	// ModTime contains the last modification time of the entry.
	ModTime int64

	// Size contains a total tail in bytes including sizes of all child entries.
	Size int64

	// LocalDirs contain the number of directories within the current entry. This
	// property will always be zero if the current instance represents a file.
	LocalDirs uint64

	// LocalFiles contain the number of files within the current entry. This property
	// will always be zero if the current instance represents a file.
	LocalFiles uint64

	// TotalDirs contains the total number of directories within the current
	// entry, including directories within the child entries. This property will
	// always be zero if the current instance represents a file.
	TotalDirs uint64

	// TotalFiles contains the total number of files within the current entry,
	// including files within the child entries. This property will always be
	// zero if the current instance represents a file.
	TotalFiles uint64

	// IsDir defines whether the current instance represents a dir or a file.
	IsDir bool
	// contains filtered or unexported fields
}

Entry contains the information about a single directory or a file instance within the file system. If the entry represents a directory instance, it has access to its child elements.

func NewDirEntry

func NewDirEntry(path string, modTime int64) *Entry

func NewFileEntry

func NewFileEntry(path string, size int64, modTime int64) *Entry

func (*Entry) AddChild

func (e *Entry) AddChild(child *Entry)

AddChild adds the provided *Entry instance to a list of child entries. The counters will be updated respectively depending on the type of child entry.

func (*Entry) Copy added in v0.3.0

func (e *Entry) Copy() *Entry

func (*Entry) Diff added in v0.3.0

func (e *Entry) Diff(ne *Entry) *Diff

func (*Entry) Entries added in v0.1.0

func (e *Entry) Entries() iter.Seq[*Entry]

Entries returns an iterator for all the current node's child elements.

func (*Entry) EntriesByType added in v0.3.0

func (e *Entry) EntriesByType(dirs bool) iter.Seq[*Entry]

EntriesByType returns an iterator for the current node's child elements. Depending on the provided argument, the iterator yields either directories or files.

func (*Entry) Ext

func (e *Entry) Ext() string

func (*Entry) GetChild

func (e *Entry) GetChild(name string) *Entry

GetChild tries to find a child element by its name. The search will be done only on the first level of the child entries. If such an entry was not found, a nil value will be returned.

func (*Entry) HasChild

func (e *Entry) HasChild() bool

func (*Entry) Name

func (e *Entry) Name() string

func (*Entry) SortChild

func (e *Entry) SortChild() *Entry

type EntryList added in v0.3.0

type EntryList []*Entry

EntryList contains a set of *Entry instances. It can represent a list of child entries.

func (EntryList) Diff added in v0.3.0

func (el EntryList) Diff(newList EntryList) *Diff

Diff returns the delta between the current and the provided EntryList instances. As a result, it returns the Diff instance containing Diff.Added, Diff.Removed, and Diff.Same entries.

It uses a straightforward approach by comparing the EntryList items one by one for each set. If there is an item in the provided EntryList that does not exist in the current EntryList, then it is considered to be "added".

type EntryPair added in v0.3.0

type EntryPair [2]*Entry

type EntrySizeHeap added in v0.1.0

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

EntrySizeHeap contains a list of the biggest dirs or files found on a specific drive/volume. It implements the heap.Interface, hence it persists entries sorted by their sizes. The EntrySizeHeap could contain up to n files, where n is defined when creating a new heap instance.

func (*EntrySizeHeap) Len added in v0.1.0

func (esh *EntrySizeHeap) Len() int

func (*EntrySizeHeap) Less added in v0.1.0

func (esh *EntrySizeHeap) Less(i, j int) bool

func (*EntrySizeHeap) Pop added in v0.1.0

func (esh *EntrySizeHeap) Pop() (v any)

func (*EntrySizeHeap) Push added in v0.1.0

func (esh *EntrySizeHeap) Push(v any)

func (*EntrySizeHeap) PushSafe added in v0.1.0

func (esh *EntrySizeHeap) PushSafe(e *Entry)

PushSafe provides a thread-safe method for adding elements to the heap. On each call, it will check the current number of items and pop the oldest.

func (*EntrySizeHeap) Reset added in v0.1.0

func (esh *EntrySizeHeap) Reset()

func (*EntrySizeHeap) Swap added in v0.1.0

func (esh *EntrySizeHeap) Swap(i, j int)

type TopEntries added in v0.3.0

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

func NewTopEntries added in v0.3.0

func NewTopEntries(maxEntries int) *TopEntries

func (*TopEntries) Dirs added in v0.3.0

func (te *TopEntries) Dirs() heap.Interface

func (*TopEntries) Files added in v0.3.0

func (te *TopEntries) Files() heap.Interface

func (*TopEntries) ScanDirs added in v0.3.0

func (te *TopEntries) ScanDirs(root *Entry)

func (*TopEntries) ScanFiles added in v0.3.0

func (te *TopEntries) ScanFiles(root *Entry)

type Tree added in v0.1.0

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

Tree provides a set of method for building and traversing the *Entry tree.

func NewTree added in v0.1.0

func NewTree(root *Entry, opts ...TreeOpt) *Tree

func (*Tree) CalculateSize added in v0.1.0

func (t *Tree) CalculateSize()

CalculateSize calculates the total number of directories and files, including ones within child entries, and the total tail of the current entry instance. This function call will recursively calculate the sizes of child entries. The final [Entry.Size] field will be a sum of all nested files sizes. If the current entry represents a file, only its own tail will be returned.

func (*Tree) PersistCache added in v0.2.0

func (t *Tree) PersistCache() error

func (*Tree) Root added in v0.1.0

func (t *Tree) Root() *Entry

Root returns a root *Entry node for the current tree.

func (*Tree) SetRoot added in v0.1.0

func (t *Tree) SetRoot(root *Entry)

SetRoot changes the current root of the tree instance.

func (*Tree) Traverse added in v0.1.0

func (t *Tree) Traverse(skipCache bool) error

Traverse traverses the current root entry instance for all internal files, and directories and builds the corresponding tree using a BFS approach. The total traverse duration depends on the directory's structure depth.

The traverse process only builds the tree structure of child entries and does not calculate the final values for total tail and number of child directories and files. To do this, the Tree.CalculateSize must be called during or after the traverse finishes the execution. In the first case, the numbers will not be accurate but can be used to display the progress of the traversing process gradually.

func (*Tree) TraverseAsync added in v0.1.0

func (t *Tree) TraverseAsync(skipCache bool) (chan struct{}, chan error)

type TreeOpt added in v0.1.0

type TreeOpt func(*Tree)

TreeOpt defines a custom type for configuring a *Tree instance.

func WithCache added in v0.2.0

func WithCache(c *cache.Cache) TreeOpt

func WithExclude added in v0.1.0

func WithExclude(exclude []string) TreeOpt

WithExclude allows setting a list of directory names that must be excluded from the traversal during the tree build-up process. The directory name can represent an absolute path or just a part of the name. In the last case, all directories that contain this name will be excluded. For example, the following path "dir/sub_dir/inner/other" and adding the name "sub" for exclusion will completely remove the "dir/sub_dir" directory from traversal. To avoid that, use a more specific path, e.g., "dir/sub/".

func WithFileInfoFilter added in v0.1.2

func WithFileInfoFilter(fl []drive.FileInfoFilter) TreeOpt

WithFileInfoFilter allows setting a list of filters for a drive.FileInfo instances. The filters will be applied during the tree traversal and discard nodes that do not meet the specific filter's specification.

The Tree instance does not dictate the filter behavior; hence, the entire filtration logic is defined within each drive.FileInfoFilter filter.

func WithPartialRoot added in v0.2.0

func WithPartialRoot() TreeOpt

Jump to

Keyboard shortcuts

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