filetree

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffType

type DiffType int

DiffType defines the comparison result between two FileNodes

const (
	Unchanged DiffType = iota
	Changed
	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 FileInfo

type FileInfo struct {
	Path      string
	TypeFlag  byte
	MD5sum    [16]byte
	TarHeader tar.Header
}

FileInfo contains tar metadata for a specific FileNode

func NewFileInfo

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

NewFileInfo 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
	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, possible 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) 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) 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) 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
}

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

func NewFileTree

func NewFileTree() (tree *FileTree)

NewFileTree creates an empty FileTree

func StackRange

func StackRange(trees []*FileTree, start, stop int) *FileTree

StackRange combines an array of trees into a single tree

func (*FileTree) AddPath

func (tree *FileTree) AddPath(path string, data FileInfo) (*FileNode, error)

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

func (*FileTree) Compare

func (tree *FileTree) Compare(upper *FileTree) error

Compare 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) 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 uint, showAttributes bool) string

StringBetween returns a partial tree in an ASCII representation.

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 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