Esempio n. 1
0
//search serches nearest and bigger than stamp and update all DAG after calling func f if needed.
func (t *Thread) search(root *merkledag.Node, stamp time.Time,
	f func(bool, *merkledag.Node) (bool, error)) (*merkledag.Node, error) {
	link, err := getLinkName(root)
	if log.If(err) {
		return nil, err
	}
	var eq bool
	if link != nil {
		eq = link.stamp.Equal(stamp)
	}
	if link == nil || (eq || link.stamp.Before(stamp)) {
		updated, errr := f(eq, root)
		log.If(errr)
		if updated {
			return root, errr
		}
		return nil, errr
	}
	n, err := t.self.GetLinkedNode(root, link.string())
	if log.If(err) {
		return nil, err
	}
	updated, err := t.search(n, stamp, f)
	if err != nil {
		return nil, err
	}
	if updated != nil {
		root, err = root.UpdateNodeLink(link.string(), updated)
		log.If(err)
		return root, err
	}
	return nil, err
}