From e047b58a33d23785cd8e40bb51536f784db0bc72 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Mon, 16 Apr 2018 17:49:54 -0300 Subject: [PATCH] dag: deduplicate AddNodeLinkClean into AddNodeLink `AddNodeLink` used to cache the linked node whereas `AddNodeLinkClean` did not, however, at some point the former was changed to do the same thing as the latter (i.e., not cache the linked node). That is, they now do the same thing so there's no reason to have both. The name `AddNodeLink` is preserved, even though it used to imply the cache functionality contrasting with the `Clean` suffix of `AddNodeLinkClean`, with this function removed the cache connotation doesn't hold anymore. License: MIT Signed-off-by: Lucas Molas --- core/coreunix/metadata.go | 2 +- importer/helpers/helpers.go | 2 +- merkledag/merkledag_test.go | 14 +++++++------- merkledag/node.go | 13 ------------- merkledag/utils/utils.go | 6 +++--- pin/pin_test.go | 2 +- pin/set_test.go | 2 +- tar/format.go | 2 +- unixfs/io/dirbuilder.go | 2 +- unixfs/mod/dagmodifier.go | 2 +- 10 files changed, 17 insertions(+), 30 deletions(-) diff --git a/core/coreunix/metadata.go b/core/coreunix/metadata.go index fbea51c21..c704db981 100644 --- a/core/coreunix/metadata.go +++ b/core/coreunix/metadata.go @@ -25,7 +25,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error } mdnode.SetData(mdata) - if err := mdnode.AddNodeLinkClean("file", nd); err != nil { + if err := mdnode.AddNodeLink("file", nd); err != nil { return "", err } diff --git a/importer/helpers/helpers.go b/importer/helpers/helpers.go index a6d8ca069..3f51d325a 100644 --- a/importer/helpers/helpers.go +++ b/importer/helpers/helpers.go @@ -109,7 +109,7 @@ func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error { // Add a link to this node without storing a reference to the memory // This way, we avoid nodes building up and consuming all of our RAM - err = n.node.AddNodeLinkClean("", childnode) + err = n.node.AddNodeLink("", childnode) if err != nil { return err } diff --git a/merkledag/merkledag_test.go b/merkledag/merkledag_test.go index 181ccbb88..ac4805363 100644 --- a/merkledag/merkledag_test.go +++ b/merkledag/merkledag_test.go @@ -340,7 +340,7 @@ func TestFetchFailure(t *testing.T) { t.Fatal(err) } - err = top.AddNodeLinkClean(fmt.Sprintf("AA%d", i), nd) + err = top.AddNodeLink(fmt.Sprintf("AA%d", i), nd) if err != nil { t.Fatal(err) } @@ -353,7 +353,7 @@ func TestFetchFailure(t *testing.T) { t.Fatal(err) } - err = top.AddNodeLinkClean(fmt.Sprintf("BB%d", i), nd) + err = top.AddNodeLink(fmt.Sprintf("BB%d", i), nd) if err != nil { t.Fatal(err) } @@ -597,19 +597,19 @@ func TestEnumerateAsyncFailsNotFound(t *testing.T) { } parent := new(ProtoNode) - if err := parent.AddNodeLinkClean("a", a); err != nil { + if err := parent.AddNodeLink("a", a); err != nil { t.Fatal(err) } - if err := parent.AddNodeLinkClean("b", b); err != nil { + if err := parent.AddNodeLink("b", b); err != nil { t.Fatal(err) } - if err := parent.AddNodeLinkClean("c", c); err != nil { + if err := parent.AddNodeLink("c", c); err != nil { t.Fatal(err) } - if err := parent.AddNodeLinkClean("d", d); err != nil { + if err := parent.AddNodeLink("d", d); err != nil { t.Fatal(err) } @@ -696,7 +696,7 @@ func mkNodeWithChildren(getChild func() *ProtoNode, width int) *ProtoNode { for i := 0; i < width; i++ { c := getChild() - if err := cur.AddNodeLinkClean(fmt.Sprint(i), c); err != nil { + if err := cur.AddNodeLink(fmt.Sprint(i), c); err != nil { panic(err) } } diff --git a/merkledag/node.go b/merkledag/node.go index a33dfcf6c..5ff66e76c 100644 --- a/merkledag/node.go +++ b/merkledag/node.go @@ -104,19 +104,6 @@ func (n *ProtoNode) AddNodeLink(name string, that ipld.Node) error { return nil } -// AddNodeLinkClean adds a link to another node. without keeping a reference to -// the child node -func (n *ProtoNode) AddNodeLinkClean(name string, that ipld.Node) error { - n.encoded = nil - lnk, err := ipld.MakeLink(that) - if err != nil { - return err - } - n.AddRawLink(name, lnk) - - return nil -} - // AddRawLink adds a copy of a link to this node func (n *ProtoNode) AddRawLink(name string, l *ipld.Link) error { n.encoded = nil diff --git a/merkledag/utils/utils.go b/merkledag/utils/utils.go index d6ac9726a..5e0e3b352 100644 --- a/merkledag/utils/utils.go +++ b/merkledag/utils/utils.go @@ -75,7 +75,7 @@ func addLink(ctx context.Context, ds ipld.DAGService, root *dag.ProtoNode, child // ensure no link with that name already exists _ = root.RemoveNodeLink(childname) // ignore error, only option is ErrNotFound - if err := root.AddNodeLinkClean(childname, childnd); err != nil { + if err := root.AddNodeLink(childname, childnd); err != nil { return nil, err } @@ -127,7 +127,7 @@ func (e *Editor) insertNodeAtPath(ctx context.Context, root *dag.ProtoNode, path _ = e.tmp.Remove(ctx, root.Cid()) _ = root.RemoveNodeLink(path[0]) - err = root.AddNodeLinkClean(path[0], ndprime) + err = root.AddNodeLink(path[0], ndprime) if err != nil { return nil, err } @@ -186,7 +186,7 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string) e.tmp.Remove(ctx, root.Cid()) _ = root.RemoveNodeLink(path[0]) - err = root.AddNodeLinkClean(path[0], nnode) + err = root.AddNodeLink(path[0], nnode) if err != nil { return nil, err } diff --git a/pin/pin_test.go b/pin/pin_test.go index 94da70ed3..e6a8a0850 100644 --- a/pin/pin_test.go +++ b/pin/pin_test.go @@ -340,7 +340,7 @@ func TestPinRecursiveFail(t *testing.T) { a, _ := randNode() b, _ := randNode() - err := a.AddNodeLinkClean("child", b) + err := a.AddNodeLink("child", b) if err != nil { t.Fatal(err) } diff --git a/pin/set_test.go b/pin/set_test.go index 815322796..4fea86bd2 100644 --- a/pin/set_test.go +++ b/pin/set_test.go @@ -74,7 +74,7 @@ func TestSet(t *testing.T) { // weird wrapper node because loadSet expects us to pass an // object pointing to multiple named sets setroot := &dag.ProtoNode{} - err = setroot.AddNodeLinkClean("foo", out) + err = setroot.AddNodeLink("foo", out) if err != nil { t.Fatal(err) } diff --git a/tar/format.go b/tar/format.go index ae004a0c9..cf06180f8 100644 --- a/tar/format.go +++ b/tar/format.go @@ -69,7 +69,7 @@ func ImportTar(ctx context.Context, r io.Reader, ds ipld.DAGService) (*dag.Proto return nil, err } - err = header.AddNodeLinkClean("data", nd) + err = header.AddNodeLink("data", nd) if err != nil { return nil, err } diff --git a/unixfs/io/dirbuilder.go b/unixfs/io/dirbuilder.go index 616617dee..e8cbff52d 100644 --- a/unixfs/io/dirbuilder.go +++ b/unixfs/io/dirbuilder.go @@ -103,7 +103,7 @@ func (d *Directory) AddChild(ctx context.Context, name string, nd ipld.Node) err if d.shard == nil { if !UseHAMTSharding { _ = d.dirnode.RemoveNodeLink(name) - return d.dirnode.AddNodeLinkClean(name, nd) + return d.dirnode.AddNodeLink(name, nd) } err := d.switchToSharding(ctx) diff --git a/unixfs/mod/dagmodifier.go b/unixfs/mod/dagmodifier.go index 0fe9df1e4..edf05ecba 100644 --- a/unixfs/mod/dagmodifier.go +++ b/unixfs/mod/dagmodifier.go @@ -561,7 +561,7 @@ func dagTruncate(ctx context.Context, n ipld.Node, size uint64, ds ipld.DAGServi } nd.SetLinks(nd.Links()[:end]) - err = nd.AddNodeLinkClean("", modified) + err = nd.AddNodeLink("", modified) if err != nil { return nil, err }