fstree

package module
v0.0.0-...-8002b46 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDeleteRoot = errors.New("cannot delete root")
	ErrLocked     = errors.New("path is locked")
	ErrUnlocked   = errors.New("path is unlocked")
	ErrExist      = fs.ErrExist
	ErrNotExist   = fs.ErrNotExist
)

Functions

func CleanPath

func CleanPath(path, separator string) string

func SplitPath

func SplitPath(rootPath, separator, path string) []string

Types

type AddMismatchedIsDir

type AddMismatchedIsDir struct {
	Expected bool
	Got      bool
}

func (*AddMismatchedIsDir) Error

func (e *AddMismatchedIsDir) Error() string

type Entry

type Entry struct {
	Name     string
	IsDir    bool
	Children []*Entry
	Locked   bool
}

Entry represents a file tree node.

func (*Entry) Copy

func (n *Entry) Copy() *Entry

Copy deep copies the current node.

type Tree

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

func New

func New(rootPath, separator string) *Tree

func (*Tree) Add

func (t *Tree) Add(path string, isDir bool) error

Add adds the path to the tree. isDir specifies if the leaf is a directory. Any directories in the path will be created if they do not exist. Returns ErrExist if attempting to add a leaf that already exists. Returns AddMismatchedIsDir if mismatched isDir values are encountered.

func (*Tree) Copy

func (t *Tree) Copy() []*Entry

func (*Tree) Exists

func (t *Tree) Exists(path string) (isDir bool, exists bool)

Exists returns true if the path exists, or false if it does not.

func (*Tree) IsLocked

func (t *Tree) IsLocked(path string) error

IsLocked takes a path and returns one of three errors depending on the status of the path: - ErrLocked if the path is locked. - ErrUnlocked if the path is unlocked. - ErrNotExist if the path does not exist.

func (*Tree) Lock

func (t *Tree) Lock(path string) error

Lock locks the given path. Returns true if the operation was successful. The error will be ErrNotExist if the path does not exist.

func (*Tree) Remove

func (t *Tree) Remove(path string) error

Remove removes the path from the tree. Returns ErrNotExist if the path is not found. Returns ErrDeleteRoot if the path is empty.

func (*Tree) Unlock

func (t *Tree) Unlock(path string) error

Unlock unlocks the given path. Returns true if the operation was successful. The error will be ErrNotExist if the path does not exist.

Jump to

Keyboard shortcuts

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