2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 13:17:42 +00:00

Remove sentinel errors

This commit is contained in:
Alexander Neumann 2016-09-01 22:08:45 +02:00
parent debf1fce54
commit 5d7b38cabf

View File

@ -9,15 +9,12 @@ import (
"restic/debug" "restic/debug"
) )
// Tree is an ordered list of nodes.
type Tree struct { type Tree struct {
Nodes []*Node `json:"nodes"` Nodes []*Node `json:"nodes"`
} }
var ( // NewTree creates a new tree object.
ErrNodeNotFound = errors.New("named node not found")
ErrNodeAlreadyInTree = errors.New("node already present")
)
func NewTree() *Tree { func NewTree() *Tree {
return &Tree{ return &Tree{
Nodes: []*Node{}, Nodes: []*Node{},
@ -61,10 +58,11 @@ func (t Tree) Equals(other *Tree) bool {
return true return true
} }
// Insert adds a new node at the correct place in the tree.
func (t *Tree) Insert(node *Node) error { func (t *Tree) Insert(node *Node) error {
pos, _, err := t.binarySearch(node.Name) pos, _, err := t.binarySearch(node.Name)
if err == nil { if err == nil {
return ErrNodeAlreadyInTree return errors.New("node already present")
} }
// https://code.google.com/p/go-wiki/wiki/SliceTricks // https://code.google.com/p/go-wiki/wiki/SliceTricks
@ -84,7 +82,7 @@ func (t Tree) binarySearch(name string) (int, *Node, error) {
return pos, t.Nodes[pos], nil return pos, t.Nodes[pos], nil
} }
return pos, nil, ErrNodeNotFound return pos, nil, errors.New("named node not found")
} }
func (t Tree) Find(name string) (*Node, error) { func (t Tree) Find(name string) (*Node, error) {