tree

package
v1.15.13 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tree implements a tree for displaying hierarchical password store entries. It is loosely based on https://github.com/restic/restic/blob/master/internal/restic/tree.go

Index

Constants

View Source
const (
	// INF allows to have a full recursion until the leaves of a tree.
	INF = -1
)

Variables

View Source
var ErrNodePresent = fmt.Errorf("node already present")

ErrNodePresent is returned when a node with the same name is already present.

View Source
var (
	// ErrNotFound is returned when a node is not found.
	ErrNotFound = fmt.Errorf("not found")
)

Functions

This section is empty.

Types

type Node

type Node struct {
	Name     string
	Leaf     bool
	Template bool
	Mount    bool
	Path     string
	Subtree  *Tree
}

Node is a tree node.

func (Node) Equals

func (n Node) Equals(other Node) bool

Equals compares to another node.

func (*Node) Len

func (n *Node) Len() int

Len returns the length of this subtree.

func (Node) Merge added in v1.14.7

func (n Node) Merge(other Node) *Node

Merge will merge two nodes into a new node. Does not change either of the two input nodes. The merged node will be in the returned node. Implements semantics specific to gopass' tree model, i.e. mounts shadow (erase) everything below a mount point, nodes within a tree can be leafs (i.e. contain a secret as well as subdirectories) and any node can also contain a template.

type Nodes

type Nodes []*Node

Nodes is a slice of nodes which can be sorted.

func (Nodes) Len

func (n Nodes) Len() int

func (Nodes) Less

func (n Nodes) Less(i, j int) bool

func (Nodes) Swap

func (n Nodes) Swap(i, j int)

type Root

type Root struct {
	Name    string
	Subtree *Tree
	Prefix  string
}

Root is the root of a tree. It contains a name and a subtree.

func New

func New(name string) *Root

New creates a new tree.

func (*Root) AddFile

func (r *Root) AddFile(path string, _ string) error

AddFile adds a new file to the tree.

func (*Root) AddMount

func (r *Root) AddMount(path, dest string) error

AddMount adds a new mount point to the tree.

func (*Root) AddTemplate

func (r *Root) AddTemplate(path string) error

AddTemplate adds a template to the tree.

func (*Root) FindFolder

func (r *Root) FindFolder(path string) (*Root, error)

FindFolder returns the subtree rooted at path.

func (*Root) Format

func (r *Root) Format(maxDepth int) string

Format returns a pretty printed string of all nodes in and below this node, e.g. `├── baz`.

func (*Root) Len

func (r *Root) Len() int

Len returns the number of entries in this folder and all subfolder including this folder itself.

func (*Root) List

func (r *Root) List(maxDepth int) []string

List returns a flat list of all files in this tree.

func (*Root) ListFolders

func (r *Root) ListFolders(maxDepth int) []string

ListFolders returns a flat list of all folders in this tree.

func (*Root) SetName

func (r *Root) SetName(n string)

SetName changes the name of this tree.

func (*Root) String

func (r *Root) String() string

String returns the name of this tree.

type Tree

type Tree struct {
	Nodes []*Node
}

Tree is a tree.

func NewTree

func NewTree() *Tree

NewTree creates a new tree.

func (*Tree) Equals

func (t *Tree) Equals(other *Tree) bool

Equals compares to another tree.

func (*Tree) Insert

func (t *Tree) Insert(other *Node) *Node

Insert adds a new node at the right position.

func (*Tree) Sort

func (t *Tree) Sort()

Sort ensures this tree is sorted.

func (*Tree) String

func (t *Tree) String() string

String returns the name of this tree.

Jump to

Keyboard shortcuts

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