walker

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipNode = errors.New("skip this node")

ErrSkipNode is returned by WalkFunc when a dir node should not be walked.

Functions

func NewSnapshotSizeRewriter added in v0.17.0

func NewSnapshotSizeRewriter(rewriteNode NodeRewriteFunc) (*TreeRewriter, QueryRewrittenSizeFunc)

func Walk

func Walk(ctx context.Context, repo restic.BlobLoader, root restic.ID, visitor WalkVisitor) error

Walk calls walkFn recursively for each node in root. If walkFn returns an error, it is passed up the call stack. The trees in ignoreTrees are not walked. If walkFn ignores trees, these are added to the set.

Types

type BlobLoadSaver added in v0.15.0

type BlobLoadSaver interface {
	restic.BlobSaver
	restic.BlobLoader
}

type FailedTreeRewriteFunc added in v0.16.0

type FailedTreeRewriteFunc func(nodeID restic.ID, path string, err error) (restic.ID, error)

type NodeRewriteFunc added in v0.16.0

type NodeRewriteFunc func(node *restic.Node, path string) *restic.Node

type QueryRewrittenSizeFunc added in v0.17.0

type QueryRewrittenSizeFunc func() SnapshotSize

type RewriteOpts added in v0.16.0

type RewriteOpts struct {
	// return nil to remove the node
	RewriteNode NodeRewriteFunc
	// decide what to do with a tree that could not be loaded. Return nil to remove the node. By default the load error is returned which causes the operation to fail.
	RewriteFailedTree FailedTreeRewriteFunc

	AllowUnstableSerialization bool
	DisableNodeCache           bool
}

type SnapshotSize added in v0.17.0

type SnapshotSize struct {
	FileCount uint
	FileSize  uint64
}

type TreeRewriter added in v0.16.0

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

func NewTreeRewriter added in v0.16.0

func NewTreeRewriter(opts RewriteOpts) *TreeRewriter

func (*TreeRewriter) RewriteTree added in v0.16.0

func (t *TreeRewriter) RewriteTree(ctx context.Context, repo BlobLoadSaver, nodepath string, nodeID restic.ID) (newNodeID restic.ID, err error)

type WalkFunc

type WalkFunc func(parentTreeID restic.ID, path string, node *restic.Node, nodeErr error) (err error)

WalkFunc is the type of the function called for each node visited by Walk. Path is the slash-separated path from the root node. If there was a problem loading a node, err is set to a non-nil error. WalkFunc can chose to ignore it by returning nil.

When the special value ErrSkipNode is returned and node is a dir node, it is not walked. When the node is not a dir node, the remaining items in this tree are skipped.

type WalkVisitor added in v0.17.0

type WalkVisitor struct {
	// If the node is a `dir`, it will be entered afterwards unless `ErrSkipNode`
	// was returned. This function is mandatory
	ProcessNode WalkFunc
	// Optional callback
	LeaveDir func(path string)
}

Jump to

Keyboard shortcuts

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