filetree

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ByName = iota
	BySizeDesc

	NumSortOrderConventions
)
View Source
const (
	AttributeFormat = "%s%s %11s %10s "
)

Variables

View Source
var GlobalFileTreeCollapse bool

Functions

func StackTreeRange

func StackTreeRange(trees []*FileTree, start, stop int) (*FileTree, []PathError, error)

StackTreeRange combines an array of trees into a single tree

Types

type Comparer

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

func NewComparer

func NewComparer(refTrees []*FileTree) Comparer

func (*Comparer) AggregatedIndexes

func (cmp *Comparer) AggregatedIndexes() <-chan TreeIndexKey

case 2: aggregated compare (bottom tree is ENTIRELY fixed, top tree SIZE changes)

func (*Comparer) BuildCache

func (cmp *Comparer) BuildCache() (errors []error)

func (*Comparer) GetPathErrors

func (cmp *Comparer) GetPathErrors(key TreeIndexKey) ([]PathError, error)

func (*Comparer) GetTree

func (cmp *Comparer) GetTree(key TreeIndexKey) (*FileTree, error)

func (*Comparer) NaturalIndexes

func (cmp *Comparer) NaturalIndexes() <-chan TreeIndexKey

case 1: layer compare (top tree SIZE is fixed (BUT floats forward), Bottom tree SIZE changes)

type DiffType

type DiffType int

DiffType defines the comparison result between two FileNodes

const (
	Unmodified DiffType = iota
	Modified
	Added
	Removed
)

func (DiffType) String

func (diff DiffType) String() string

String of a DiffType

type EfficiencyData

type EfficiencyData struct {
	Path           string
	Nodes          []*FileNode
	CumulativeSize int64
	// contains filtered or unexported fields
}

EfficiencyData represents the storage and reference statistics for a given file tree path.

type EfficiencySlice

type EfficiencySlice []*EfficiencyData

EfficiencySlice represents an ordered set of EfficiencyData data structures.

func Efficiency

func Efficiency(trees []*FileTree) (float64, EfficiencySlice)

Efficiency returns the score and file set of the given set of FileTrees (layers). This is loosely based on: 1. Files that are duplicated across layers discounts your score, weighted by file size 2. Files that are removed discounts your score, weighted by the original file size

func (EfficiencySlice) Len

func (efs EfficiencySlice) Len() int

Len is required for sorting.

func (EfficiencySlice) Less

func (efs EfficiencySlice) Less(i, j int) bool

Less comparison is required for sorting.

func (EfficiencySlice) Swap

func (efs EfficiencySlice) Swap(i, j int)

Swap operation is required for sorting.

type FileAction

type FileAction int
const (
	ActionAdd FileAction = iota
	ActionRemove
)

func (FileAction) String

func (fa FileAction) String() string

type FileInfo

type FileInfo struct {
	Path     string
	TypeFlag byte
	Linkname string

	Size  int64
	Mode  os.FileMode
	Uid   int
	Gid   int
	IsDir bool
	// contains filtered or unexported fields
}

FileInfo contains tar metadata for a specific FileNode

func NewFileInfo

func NewFileInfo(realPath, path string, info os.FileInfo) FileInfo

func NewFileInfoFromTarHeader

func NewFileInfoFromTarHeader(reader *tar.Reader, header *tar.Header, path string) FileInfo

NewFileInfoFromTarHeader extracts the metadata from a tar header and file contents and generates a new FileInfo object.

func (*FileInfo) Compare

func (data *FileInfo) Compare(other FileInfo) DiffType

Compare determines the DiffType between two FileInfos based on the type and contents of each given FileInfo

func (*FileInfo) Copy

func (data *FileInfo) Copy() *FileInfo

Copy duplicates a FileInfo

type FileNode

type FileNode struct {
	Tree     *FileTree
	Parent   *FileNode
	Size     int64 // memoized total size of file or directory
	Name     string
	Data     NodeData
	Children map[string]*FileNode
	// contains filtered or unexported fields
}

FileNode represents a single file, its relation to files beneath it, the tree it exists in, and the metadata of the given file.

func NewNode

func NewNode(parent *FileNode, name string, data FileInfo) (node *FileNode)

NewNode creates a new FileNode relative to the given parent node with a payload.

func (*FileNode) AddChild

func (node *FileNode) AddChild(name string, data FileInfo) (child *FileNode)

AddChild creates a new node relative to the current FileNode.

func (*FileNode) AssignDiffType

func (node *FileNode) AssignDiffType(diffType DiffType) error

AssignDiffType will assign the given DiffType to this node, possibly affecting child nodes.

func (*FileNode) Copy

func (node *FileNode) Copy(parent *FileNode) *FileNode

Copy duplicates the existing node relative to a new parent node.

func (*FileNode) GetSize

func (node *FileNode) GetSize() int64

func (*FileNode) IsLeaf

func (node *FileNode) IsLeaf() bool

IsLeaf returns true is the current node has no child nodes.

func (*FileNode) IsWhiteout

func (node *FileNode) IsWhiteout() bool

IsWhiteout returns an indication if this file may be a overlay-whiteout file.

func (*FileNode) MetadataString

func (node *FileNode) MetadataString() string

MetadatString returns the FileNode metadata in a columnar string.

func (*FileNode) Path

func (node *FileNode) Path() string

Path returns a slash-delimited string from the root of the greater tree to the current node (e.g. /a/path/to/here)

func (*FileNode) Remove

func (node *FileNode) Remove() error

Remove deletes the current FileNode from it's parent FileNode's relations.

func (*FileNode) String

func (node *FileNode) String() string

String shows the filename formatted into the proper color (by DiffType), additionally indicating if it is a symlink.

func (*FileNode) VisitDepthChildFirst

func (node *FileNode) VisitDepthChildFirst(visitor Visitor, evaluator VisitEvaluator, sorter OrderStrategy) error

VisitDepthChildFirst iterates a tree depth-first (starting at this FileNode), evaluating the deepest depths first (visit on bubble up)

func (*FileNode) VisitDepthParentFirst

func (node *FileNode) VisitDepthParentFirst(visitor Visitor, evaluator VisitEvaluator, sorter OrderStrategy) error

VisitDepthParentFirst iterates a tree depth-first (starting at this FileNode), evaluating the shallowest depths first (visit while sinking down)

type FileTree

type FileTree struct {
	Root      *FileNode
	Size      int
	FileSize  uint64
	Name      string
	Id        uuid.UUID
	SortOrder SortOrder
}

FileTree represents a set of files, directories, and their relations.

func NewFileTree

func NewFileTree() (tree *FileTree)

NewFileTree creates an empty FileTree

func (*FileTree) AddPath

func (tree *FileTree) AddPath(filepath string, data FileInfo) (*FileNode, []*FileNode, error)

AddPath adds a new node to the tree with the given payload

func (*FileTree) CompareAndMark

func (tree *FileTree) CompareAndMark(upper *FileTree) ([]PathError, error)

CompareAndMark marks the FileNodes in the owning (lower) tree with DiffType annotations when compared to the given (upper) tree.

func (*FileTree) Copy

func (tree *FileTree) Copy() *FileTree

Copy returns a copy of the given FileTree

func (*FileTree) GetNode

func (tree *FileTree) GetNode(path string) (*FileNode, error)

GetNode fetches a single node when given a slash-delimited string from root ('/') to the desired node (e.g. '/a/node/path')

func (*FileTree) RemovePath

func (tree *FileTree) RemovePath(path string) error

RemovePath removes a node from the tree given its path.

func (*FileTree) Stack

func (tree *FileTree) Stack(upper *FileTree) (failed []PathError, stackErr error)

Stack takes two trees and combines them together. This is done by "stacking" the given tree on top of the owning tree.

func (*FileTree) String

func (tree *FileTree) String(showAttributes bool) string

String returns the entire tree in an ASCII representation.

func (*FileTree) StringBetween

func (tree *FileTree) StringBetween(start, stop int, showAttributes bool) string

StringBetween returns a partial tree in an ASCII representation.

func (*FileTree) VisibleSize

func (tree *FileTree) VisibleSize() int

func (*FileTree) VisitDepthChildFirst

func (tree *FileTree) VisitDepthChildFirst(visitor Visitor, evaluator VisitEvaluator) error

VisitDepthChildFirst iterates the given tree depth-first, evaluating the deepest depths first (visit on bubble up)

func (*FileTree) VisitDepthParentFirst

func (tree *FileTree) VisitDepthParentFirst(visitor Visitor, evaluator VisitEvaluator) error

VisitDepthParentFirst iterates the given tree depth-first, evaluating the shallowest depths first (visit while sinking down)

type NodeData

type NodeData struct {
	ViewInfo ViewInfo
	FileInfo FileInfo
	DiffType DiffType
}

NodeData is the payload for a FileNode

func NewNodeData

func NewNodeData() *NodeData

NewNodeData creates an empty NodeData struct for a FileNode

func (*NodeData) Copy

func (data *NodeData) Copy() *NodeData

Copy duplicates a NodeData

type OrderStrategy

type OrderStrategy interface {
	// contains filtered or unexported methods
}

func GetSortOrderStrategy

func GetSortOrderStrategy(sortOrder SortOrder) OrderStrategy

type PathError

type PathError struct {
	Path   string
	Action FileAction
	Err    error
}

func NewPathError

func NewPathError(path string, action FileAction, err error) PathError

func (PathError) String

func (pe PathError) String() string

type SortOrder

type SortOrder int

type TreeIndexKey

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

func NewTreeIndexKey

func NewTreeIndexKey(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop int) TreeIndexKey

func (TreeIndexKey) String

func (index TreeIndexKey) String() string

type ViewInfo

type ViewInfo struct {
	Collapsed bool
	Hidden    bool
}

ViewInfo contains UI specific detail for a specific FileNode

func NewViewInfo

func NewViewInfo() (view *ViewInfo)

NewViewInfo creates a default ViewInfo

func (*ViewInfo) Copy

func (view *ViewInfo) Copy() (newView *ViewInfo)

Copy duplicates a ViewInfo

type VisitEvaluator

type VisitEvaluator func(*FileNode) bool

VisitEvaluator is a function that indicates whether the given node should be visited by a Visitor.

type Visitor

type Visitor func(*FileNode) error

Visitor is a function that processes, observes, or otherwise transforms the given node

Jump to

Keyboard shortcuts

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