error variable names should start with 'Err'

This commit is contained in:
Michael Eischer 2020-07-28 22:32:57 +02:00
parent b77e933d80
commit 1ede018ea6
4 changed files with 15 additions and 15 deletions

View File

@ -270,7 +270,7 @@ func (f *Finder) findInSnapshot(ctx context.Context, sn *restic.Snapshot) error
Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
return false, walker.SkipNode
return false, walker.ErrSkipNode
}
if node == nil {
@ -314,7 +314,7 @@ func (f *Finder) findInSnapshot(ctx context.Context, sn *restic.Snapshot) error
if !childMayMatch {
ignoreIfNoMatch = true
errIfNoMatch = walker.SkipNode
errIfNoMatch = walker.ErrSkipNode
} else {
ignoreIfNoMatch = false
}
@ -354,7 +354,7 @@ func (f *Finder) findIDs(ctx context.Context, sn *restic.Snapshot) error {
Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
return false, walker.SkipNode
return false, walker.ErrSkipNode
}
if node == nil {

View File

@ -222,7 +222,7 @@ func runLs(opts LsOptions, gopts GlobalOptions, args []string) error {
// otherwise, signal the walker to not walk recursively into any
// subdirs
if node.Type == "dir" {
return false, walker.SkipNode
return false, walker.ErrSkipNode
}
return false, nil
})

View File

@ -10,15 +10,15 @@ import (
"github.com/restic/restic/internal/restic"
)
// SkipNode is returned by WalkFunc when a dir node should not be walked.
var SkipNode = errors.New("skip this node")
// ErrSkipNode is returned by WalkFunc when a dir node should not be walked.
var ErrSkipNode = errors.New("skip this node")
// 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 SkipNode is returned and node is a dir node, it is
// 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.
//
@ -26,7 +26,7 @@ var SkipNode = errors.New("skip this node")
// For tree nodes, this means that the function is not called for the
// referenced tree. If the node is not a tree, and all nodes in the current
// tree have ignore set to true, the current tree will not be visited again.
// When err is not nil and different from SkipNode, the value returned for
// When err is not nil and different from ErrSkipNode, the value returned for
// ignore is ignored.
type WalkFunc func(parentTreeID restic.ID, path string, node *restic.Node, nodeErr error) (ignore bool, err error)
@ -38,7 +38,7 @@ func Walk(ctx context.Context, repo restic.TreeLoader, root restic.ID, ignoreTre
_, err = walkFn(root, "/", nil, err)
if err != nil {
if err == SkipNode {
if err == ErrSkipNode {
err = nil
}
return err
@ -76,7 +76,7 @@ func walk(ctx context.Context, repo restic.TreeLoader, prefix string, parentTree
if node.Type != "dir" {
ignore, err := walkFn(parentTreeID, p, node, nil)
if err != nil {
if err == SkipNode {
if err == ErrSkipNode {
// skip the remaining entries in this tree
return allNodesIgnored, nil
}
@ -102,7 +102,7 @@ func walk(ctx context.Context, repo restic.TreeLoader, prefix string, parentTree
subtree, err := repo.LoadTree(ctx, *node.Subtree)
ignore, err := walkFn(parentTreeID, p, node, err)
if err != nil {
if err == SkipNode {
if err == ErrSkipNode {
if ignore {
ignoreTrees.Insert(*node.Subtree)
}

View File

@ -138,7 +138,7 @@ func checkParentTreeOrder(want []string) checkFunc {
}
}
// checkSkipFor returns SkipNode if path is in skipFor, it checks that the
// checkSkipFor returns ErrSkipNode if path is in skipFor, it checks that the
// paths the walk func is called for are exactly the ones in wantPaths.
func checkSkipFor(skipFor map[string]struct{}, wantPaths []string) checkFunc {
var pos int
@ -161,7 +161,7 @@ func checkSkipFor(skipFor map[string]struct{}, wantPaths []string) checkFunc {
pos++
if _, ok := skipFor[path]; ok {
return false, SkipNode
return false, ErrSkipNode
}
return false, nil
@ -177,7 +177,7 @@ func checkSkipFor(skipFor map[string]struct{}, wantPaths []string) checkFunc {
}
}
// checkIgnore returns SkipNode if path is in skipFor and sets ignore according
// checkIgnore returns ErrSkipNode if path is in skipFor and sets ignore according
// to ignoreFor. It checks that the paths the walk func is called for are exactly
// the ones in wantPaths.
func checkIgnore(skipFor map[string]struct{}, ignoreFor map[string]bool, wantPaths []string) checkFunc {
@ -201,7 +201,7 @@ func checkIgnore(skipFor map[string]struct{}, ignoreFor map[string]bool, wantPat
pos++
if _, ok := skipFor[path]; ok {
return ignoreFor[path], SkipNode
return ignoreFor[path], ErrSkipNode
}
return ignoreFor[path], nil