model

package
v0.0.0-...-f3071e7 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareAndMark

func CompareAndMark(treeA, treeB *FileTreeModel) error

CompareAndMark compares this treeA and treeB by performing two passages: 1: iterate over nodes in A and if they are absent in B - mark them as "deleted" 2: iterate over nodes in B and if they are absent in A - mark them as "added" *: rest of the nodes are compared for being "modified" NOTE: for every "added", "deleted" or "modified" node - all their parents are marked as well as "modified"

func GetXid

func GetXid(info os.FileInfo) (string, string)

Types

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 FileInfo

type FileInfo struct {
	// fully qualified file path: slash-delimited string from the root ('/') to the desired node (e.g. '/a/node/fqfp')
	Fqfp     string
	Linkname string

	Size int64
	Mode os.FileMode
	Uid  string // User Id - owner of the file
	Gid  string // Group Id - owner of the file
	Err  error  // error discovered while retrieving metadata about this file, such as Insufficient Permission
	// contains filtered or unexported fields
}

FileInfo contains tar metadata for a specific FileNode

func NewFileInfo

func NewFileInfo(fqfp string, info os.FileInfo, err error) FileInfo

NewFileInfo extracts the metadata from the info and file contents and generates a new FileInfo object.

func (*FileInfo) Clone

func (info *FileInfo) Clone() *FileInfo

Clone clones given FileInfo

func (*FileInfo) Compare

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

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

func (*FileInfo) IsDir

func (info *FileInfo) IsDir() bool

func (*FileInfo) String

func (info *FileInfo) String() string

type FileNode

type FileNode struct {
	Tree     *FileTreeModel
	Parent   *FileNode
	Children map[string]*FileNode
	Data     NodeData

	Name string
	// 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 NewFileNode

func NewFileNode(parent *FileNode, fqfp string, name string, info FileInfo) (node *FileNode)

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

func (*FileNode) AbsPath

func (node *FileNode) AbsPath() string

AbsPath returns a slash-delimited absolute fqfp of the given file

func (*FileNode) AddChild

func (node *FileNode) AddChild(name string, info FileInfo) *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) DepthFirstSearch

func (node *FileNode) DepthFirstSearch(visitor Visitor, evaluator VisitEvaluator) error

DepthFirstSearch starts at the tree root explores as far as possible along each branch before backtracking

func (*FileNode) IsDir

func (node *FileNode) IsDir() bool

IsDir returns true is the current node is a Directory

func (*FileNode) IsLeaf

func (node *FileNode) IsLeaf() bool

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

func (*FileNode) MetadataAsStringArray

func (node *FileNode) MetadataAsStringArray() []string

MetadataString returns the FileNode metadata for columnar representation

func (*FileNode) MetadataString

func (node *FileNode) MetadataString() string

MetadataString returns the FileNode metadata in a columnar string.

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.

type FileTreeModel

type FileTreeModel struct {
	// absolute root of the filesystem
	Root *FileNode

	// number of files and folders in this Tree
	// NOTE: this number is different from the len(pwd.Children)
	Size int

	Name string
	// contains filtered or unexported fields
}

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

func NewFileTreeModel

func NewFileTreeModel() (tree *FileTreeModel)

NewFileTreeModel creates an empty FileTreeModel

func ReadFileTree

func ReadFileTree(fqfp string) (*FileTreeModel, error)

ReadFileTree reads directory specified by the fqfp (Fully Qualified File AbsPath)

func (*FileTreeModel) AddPath

func (tree *FileTreeModel) AddPath(fqfp string, info FileInfo) (*FileNode, []*FileNode, error)

AddPath adds a new node to the tree when given fully qualified file path and optional payload

func (*FileTreeModel) Clone

func (tree *FileTreeModel) Clone() *FileTreeModel

Clone returns a copy of the given FileTreeModel

func (*FileTreeModel) DepthFirstSearch

func (tree *FileTreeModel) DepthFirstSearch(visitor Visitor, evaluator VisitEvaluator) error

DepthFirstSearch starts at the tree root explores as far as possible along each branch before backtracking

func (*FileTreeModel) GetNode

func (tree *FileTreeModel) GetNode(fqfp string) (*FileNode, error)

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

func (*FileTreeModel) GetNodeAt

func (tree *FileTreeModel) GetNodeAt(index int) *FileNode

GetNodeAt returns FileNode representing n-th element in the FileTree by the 0-based index

func (*FileTreeModel) GetNodeByName

func (tree *FileTreeModel) GetNodeByName(name string) *FileNode

GetNodeByName returns FileNode by name in the subtree represented by PWD; supports ".." name returns nil if name can not be found

func (*FileTreeModel) GetPwd

func (tree *FileTreeModel) GetPwd() string

func (*FileTreeModel) RemovePath

func (tree *FileTreeModel) RemovePath(fqfp string) error

RemovePath removes a node from the tree given its fully qualified file path - slash-delimited string from the root ('/') to the desired node (e.g. '/a/node/path.txt').

func (*FileTreeModel) SetPwd

func (tree *FileTreeModel) SetPwd(fqfp string) error

func (*FileTreeModel) String

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

String returns the entire tree in an ASCII representation.

func (*FileTreeModel) StringArrayBetween

func (tree *FileTreeModel) StringArrayBetween(start, stop int) ([][]string, []*FileNode)

StringArrayBetween returns a partial tree in an ASCII representation. start is inclusive, 0-based index pointer stop is exclusive, 0-based index pointer

func (*FileTreeModel) StringBetween

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

StringBetween returns a partial tree in an ASCII representation. start is inclusive, 0-based index pointer stop is exclusive, 0-based index pointer

func (*FileTreeModel) VisibleSize

func (tree *FileTreeModel) VisibleSize() int

type NodeData

type NodeData struct {
	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) Clone

func (data *NodeData) Clone() *NodeData

Clone duplicates a NodeData

type VisitEvaluator

type VisitEvaluator func(*FileNode) bool

VisitEvaluator is a function that returns True if 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