model

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CategoryColor

func CategoryColor(cat FileCategory) string

CategoryColor returns the theme color for a category.

func CategoryName

func CategoryName(cat FileCategory) string

CategoryName returns the display name for a category.

func GetExtension

func GetExtension(name string) string

GetExtension returns the lowercase extension of a filename.

func SortChildren

func SortChildren(children []TreeNode, cfg SortConfig, useApparent bool)

SortChildren sorts a slice of TreeNode in place according to config.

Types

type DirNode

type DirNode struct {
	FileNode
	Children  []TreeNode // Mixed files and subdirectories
	ItemCount int64      // Total recursive item count
	// contains filtered or unexported fields
}

DirNode represents a directory with children.

func (*DirNode) AddChild

func (d *DirNode) AddChild(child TreeNode)

AddChild appends a child node thread-safely.

func (*DirNode) GetChildren

func (d *DirNode) GetChildren() []TreeNode

GetChildren returns a snapshot of children thread-safely.

func (*DirNode) IsDir

func (d *DirNode) IsDir() bool

func (*DirNode) Path

func (d *DirNode) Path() string

func (*DirNode) ReadChildren added in v1.2.8

func (d *DirNode) ReadChildren() []TreeNode

ReadChildren returns the children slice directly without copying. Safe for post-scan read-only access when no concurrent writes occur.

func (*DirNode) RemoveChild

func (d *DirNode) RemoveChild(name string) bool

RemoveChild removes a child by name and updates sizes up the tree.

func (*DirNode) UpdateSize

func (d *DirNode) UpdateSize()

UpdateSize recalculates this directory's size from its children.

func (*DirNode) UpdateSizeRecursive added in v1.2.8

func (d *DirNode) UpdateSizeRecursive()

UpdateSizeRecursive performs a bottom-up size calculation. Children are updated before parents, ensuring correct totals. Must be called only after all concurrent writes are complete.

func (*DirNode) UpdateSizeRecursiveContext added in v1.3.0

func (d *DirNode) UpdateSizeRecursiveContext(ctx context.Context)

UpdateSizeRecursiveContext performs a bottom-up size calculation and stops early if the context is canceled.

type FileCategory

type FileCategory int

FileCategory represents a high-level file type category.

const (
	CatOther FileCategory = iota
	CatMedia
	CatCode
	CatArchive
	CatDocument
	CatSystem
	CatExecutable
)

func ClassifyFile

func ClassifyFile(name string) FileCategory

ClassifyFile returns the category for a given filename.

type FileNode

type FileNode struct {
	Name   string    // Relative name (not full path)
	Size   int64     // Apparent size in bytes
	Usage  int64     // Disk usage (blocks * block size)
	Mtime  time.Time // Last modification time
	Inode  uint64    // Inode number for hardlink detection
	Flag   NodeFlag
	Parent *DirNode // Parent directory (nil for root)
}

FileNode represents a single file in the tree.

func NewBrokenSymlinkNode added in v1.2.8

func NewBrokenSymlinkNode(name string, parent *DirNode) *FileNode

NewBrokenSymlinkNode creates a placeholder node for a broken symlink.

func (*FileNode) GetFlag

func (f *FileNode) GetFlag() NodeFlag

func (*FileNode) GetMtime

func (f *FileNode) GetMtime() time.Time

func (*FileNode) GetName

func (f *FileNode) GetName() string

func (*FileNode) GetParent

func (f *FileNode) GetParent() *DirNode

func (*FileNode) GetSize

func (f *FileNode) GetSize() int64

func (*FileNode) GetUsage

func (f *FileNode) GetUsage() int64

func (*FileNode) IsDir

func (f *FileNode) IsDir() bool

func (*FileNode) Path

func (f *FileNode) Path() string

type NodeFlag

type NodeFlag uint8

NodeFlag represents special file attributes.

const (
	FlagNone    NodeFlag = 0
	FlagSymlink NodeFlag = 1 << iota
	FlagError
	FlagHardlink
	// FlagUsageEstimated marks nodes whose disk usage is estimated (not exact).
	FlagUsageEstimated
)

type SortConfig

type SortConfig struct {
	Field SortField
	Order SortOrder
	// DirsFirst keeps directories before files regardless of sort.
	DirsFirst bool
}

SortConfig holds sort preferences.

func DefaultSort

func DefaultSort() SortConfig

DefaultSort returns the default sort config (size descending, dirs first).

type SortField

type SortField int

SortField defines what to sort by.

const (
	SortBySize SortField = iota
	SortByName
	SortByCount
	SortByMtime
)

type SortOrder

type SortOrder int

SortOrder defines ascending or descending.

const (
	SortDesc SortOrder = iota
	SortAsc
)

type TreeNode

type TreeNode interface {
	GetName() string
	GetSize() int64
	GetUsage() int64
	GetMtime() time.Time
	GetFlag() NodeFlag
	GetParent() *DirNode
	IsDir() bool
	Path() string
}

TreeNode is the interface satisfied by both FileNode and DirNode.

Jump to

Keyboard shortcuts

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