filetree

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxRecursionDepth limits the maximum depth of directory recursion to prevent stack overflow
	MaxRecursionDepth = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeType

type ChangeType string

ChangeType represents the type of change detected

const (
	ChangeTypeCreate ChangeType = "create"
	ChangeTypeModify ChangeType = "modify"
	ChangeTypeDelete ChangeType = "delete"
	ChangeTypeMove   ChangeType = "move"
	ChangeTypeChmod  ChangeType = "chmod"
	ChangeTypeRename ChangeType = "rename"
)

type FileChange

type FileChange struct {
	Type      ChangeType
	Path      string
	OldNode   *FileNode // nil for create
	NewNode   *FileNode // nil for delete
	Timestamp time.Time
}

FileChange represents a detected change in the file system

type FileNode

type FileNode struct {
	Name     string               // File/directory name
	Path     string               // Full path from root
	IsDir    bool                 // Whether this is a directory
	Size     int64                // File size in bytes
	Inode    uint64               // File inode number
	Device   uint64               // Device number
	Mode     uint32               // File permissions and type
	Uid      uint32               // Owner user ID
	Gid      uint32               // Owner group ID
	Mtime    time.Time            // Last modification time
	Ctime    time.Time            // Last status change time
	Children map[string]*FileNode // Child nodes (for directories)
	Parent   *FileNode            // Parent node
	// contains filtered or unexported fields
}

FileNode represents a file or directory in the tree

func NewFileNode

func NewFileNode(name, path string, isDir bool) *FileNode

NewFileNode creates a new file node

func (*FileNode) AddChild

func (n *FileNode) AddChild(child *FileNode)

AddChild adds a child node to this node

func (*FileNode) GetChild

func (n *FileNode) GetChild(name string) *FileNode

GetChild retrieves a child node by name

func (*FileNode) GetChildren

func (n *FileNode) GetChildren() map[string]*FileNode

GetChildren returns a copy of all children

func (*FileNode) HasChild

func (n *FileNode) HasChild(name string) bool

HasChild checks if a child with the given name exists

func (*FileNode) RemoveChild

func (n *FileNode) RemoveChild(name string)

RemoveChild removes a child node

func (*FileNode) SetMetadata

func (n *FileNode) SetMetadata(info os.FileInfo, stat *syscall.Stat_t)

SetMetadata sets the file metadata from os.FileInfo and syscall.Stat_t

type FileTree

type FileTree struct {
	Root      *FileNode
	NodeCount int
	// contains filtered or unexported fields
}

FileTree represents the complete file system tree

func NewFileTree

func NewFileTree() *FileTree

NewFileTree creates a new empty file tree

func (*FileTree) Clear

func (t *FileTree) Clear()

Clear removes all nodes from the tree

func (*FileTree) FindNode

func (t *FileTree) FindNode(path string) *FileNode

FindNode finds a node by path

func (*FileTree) GetNodeCount

func (t *FileTree) GetNodeCount() int

GetNodeCount returns the total number of nodes in the tree

func (*FileTree) GetRoot

func (t *FileTree) GetRoot() *FileNode

GetRoot returns the root node

func (*FileTree) IncrementNodeCount

func (t *FileTree) IncrementNodeCount()

IncrementNodeCount increments the node count

func (*FileTree) SetRoot

func (t *FileTree) SetRoot(root *FileNode)

SetRoot sets the root node of the tree

func (*FileTree) Walk

func (t *FileTree) Walk(fn func(*FileNode) error) error

Walk traverses the tree and calls the given function for each node

type SnapshotConfig

type SnapshotConfig struct {
	MaxScanDepth    int      // Maximum directory depth to scan
	IncludeHidden   bool     // Whether to include hidden files
	ExcludePatterns []string // Glob patterns to exclude
	MaxFileSize     int64    // Maximum file size to track
	FollowSymlinks  bool     // Whether to follow symbolic links
}

SnapshotConfig holds configuration for snapshot creation

type SnapshotManager

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

SnapshotManager manages file tree snapshots with size constraints

func NewSnapshotManager

func NewSnapshotManager(maxNodes int, config SnapshotConfig) *SnapshotManager

NewSnapshotManager creates a new snapshot manager

func (*SnapshotManager) Cleanup

func (sm *SnapshotManager) Cleanup()

Cleanup removes old snapshots to free memory

func (*SnapshotManager) ClearCurrentSnapshot

func (sm *SnapshotManager) ClearCurrentSnapshot()

ClearCurrentSnapshot clears the current snapshot

func (*SnapshotManager) CreateSnapshot

func (sm *SnapshotManager) CreateSnapshot(rootPath string) (*FileTree, error)

CreateSnapshot creates a new snapshot from the given root path

func (*SnapshotManager) GetCurrentSnapshot

func (sm *SnapshotManager) GetCurrentSnapshot() *FileTree

GetCurrentSnapshot returns the current snapshot

func (*SnapshotManager) GetPreviousSnapshot

func (sm *SnapshotManager) GetPreviousSnapshot() *FileTree

GetPreviousSnapshot returns the previous snapshot

func (*SnapshotManager) GetSnapshotStats

func (sm *SnapshotManager) GetSnapshotStats() (currentNodes, previousNodes int)

GetSnapshotStats returns statistics about the snapshots

func (*SnapshotManager) HasPreviousSnapshot

func (sm *SnapshotManager) HasPreviousSnapshot() bool

HasPreviousSnapshot checks if there's a previous snapshot

type TreeComparator

type TreeComparator struct {
}

TreeComparator compares two file tree snapshots and detects changes

func NewTreeComparator

func NewTreeComparator() *TreeComparator

NewTreeComparator creates a new tree comparator

func (*TreeComparator) CompareSnapshots

func (tc *TreeComparator) CompareSnapshots(oldTree, newTree *FileTree) []*FileChange

CompareSnapshots compares two snapshots and returns detected changes

func (*TreeComparator) ConvertToFimEvents

func (tc *TreeComparator) ConvertToFimEvents(changes []*FileChange, hostPath string) []fimtypes.FimEvent

ConvertToFimEvents converts file changes to FIM events

Jump to

Keyboard shortcuts

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