diff --git a/Gopkg.lock b/Gopkg.lock index 405f1a25..38f92e16 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -50,7 +50,7 @@ branch = "master" name = "github.com/hashicorp/go-immutable-radix" packages = ["."] - revision = "59b67882ec612f43b9d4c4fd97cebd507be4b3ee" + revision = "7f3cd4390caab3250a57f30efdb2a65dd7649ecf" [[projects]] branch = "master" @@ -115,7 +115,7 @@ "poly1305", "salsa20/salsa" ] - revision = "3d37316aaa6bd9929127ac9a527abf408178ea7b" + revision = "1875d0a70c90e57f11972aefd42276df65e895b9" [[projects]] branch = "master" @@ -139,7 +139,7 @@ "windows/svc/eventlog", "windows/svc/mgr" ] - revision = "ef802241c90f84d84d644a2d8d0de8ee96038c9c" + revision = "3dbebcf8efb6a5011a60c2b4591c1022a759af8a" [solve-meta] analyzer-name = "dep" diff --git a/vendor/github.com/hashicorp/go-immutable-radix/iradix.go b/vendor/github.com/hashicorp/go-immutable-radix/iradix.go index c7172c40..e5e6e57f 100644 --- a/vendor/github.com/hashicorp/go-immutable-radix/iradix.go +++ b/vendor/github.com/hashicorp/go-immutable-radix/iradix.go @@ -338,6 +338,11 @@ func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) { if !n.isLeaf() { return nil, nil } + // Copy the pointer in case we are in a transaction that already + // modified this node since the node will be reused. Any changes + // made to the node will not affect returning the original leaf + // value. + oldLeaf := n.leaf // Remove the leaf node nc := t.writeNode(n, true) @@ -347,7 +352,7 @@ func (t *Txn) delete(parent, n *Node, search []byte) (*Node, *leafNode) { if n != t.root && len(nc.edges) == 1 { t.mergeChild(nc) } - return nc, n.leaf + return nc, oldLeaf } // Look for an edge diff --git a/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go b/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go index bc9c77c2..326299de 100644 --- a/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go +++ b/vendor/github.com/hashicorp/go-immutable-radix/iradix_test.go @@ -173,7 +173,7 @@ func TestRoot(t *testing.T) { } val, ok := r.Get(nil) if !ok || val != true { - t.Fatalf("bad: %v %#v", val) + t.Fatalf("bad: %#v", val) } r, val, ok = r.Delete(nil) if !ok || val != true { @@ -1494,3 +1494,38 @@ func TestTrackMutate_cachedNodeChange(t *testing.T) { } } } + +func TestLenTxn(t *testing.T) { + r := New() + + if r.Len() != 0 { + t.Fatalf("not starting with empty tree") + } + + txn := r.Txn() + keys := []string{ + "foo/bar/baz", + "foo/baz/bar", + "foo/zip/zap", + "foobar", + "nochange", + } + for _, k := range keys { + txn.Insert([]byte(k), nil) + } + r = txn.Commit() + + if r.Len() != len(keys) { + t.Fatalf("bad: expected %d, got %d", len(keys), r.Len()) + } + + txn = r.Txn() + for _, k := range keys { + txn.Delete([]byte(k)) + } + r = txn.Commit() + + if r.Len() != 0 { + t.Fatalf("tree len should be zero, got %d", r.Len()) + } +}