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 <schomatis@gmail.com>
Lucas Molas committed
Apr 16, 2018 at 17:49 UTC
e047b58a33d23785cd8e40bb51536f784db0bc72
10 files changed
+17
-30
core/coreunix/metadata.go
+1
-1
@@ -25,7 +25,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error
25
}
26
27
mdnode.SetData(mdata)
28
- if err := mdnode.AddNodeLinkClean("file", nd); err != nil {
28
+ if err := mdnode.AddNodeLink("file", nd); err != nil {
29
return "", err
30
}
31
importer/helpers/helpers.go
+1
-1
@@ -109,7 +109,7 @@ func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error {
109
110
// Add a link to this node without storing a reference to the memory
111
// This way, we avoid nodes building up and consuming all of our RAM
112
- err = n.node.AddNodeLinkClean("", childnode)
112
+ err = n.node.AddNodeLink("", childnode)
113
if err != nil {
114
return err
115
}
merkledag/merkledag_test.go
+7
-7
@@ -340,7 +340,7 @@ func TestFetchFailure(t *testing.T) {
340
t.Fatal(err)
341
}
342
343
- err = top.AddNodeLinkClean(fmt.Sprintf("AA%d", i), nd)
343
+ err = top.AddNodeLink(fmt.Sprintf("AA%d", i), nd)
344
if err != nil {
345
t.Fatal(err)
346
}
@@ -353,7 +353,7 @@ func TestFetchFailure(t *testing.T) {
353
t.Fatal(err)
354
}
355
356
- err = top.AddNodeLinkClean(fmt.Sprintf("BB%d", i), nd)
356
+ err = top.AddNodeLink(fmt.Sprintf("BB%d", i), nd)
357
if err != nil {
358
t.Fatal(err)
359
}
@@ -597,19 +597,19 @@ func TestEnumerateAsyncFailsNotFound(t *testing.T) {
597
}
598
599
parent := new(ProtoNode)
600
- if err := parent.AddNodeLinkClean("a", a); err != nil {
600
+ if err := parent.AddNodeLink("a", a); err != nil {
601
t.Fatal(err)
602
}
603
604
- if err := parent.AddNodeLinkClean("b", b); err != nil {
604
+ if err := parent.AddNodeLink("b", b); err != nil {
605
t.Fatal(err)
606
}
607
608
- if err := parent.AddNodeLinkClean("c", c); err != nil {
608
+ if err := parent.AddNodeLink("c", c); err != nil {
609
t.Fatal(err)
610
}
611
612
- if err := parent.AddNodeLinkClean("d", d); err != nil {
612
+ if err := parent.AddNodeLink("d", d); err != nil {
613
t.Fatal(err)
614
}
615
@@ -696,7 +696,7 @@ func mkNodeWithChildren(getChild func() *ProtoNode, width int) *ProtoNode {
696
697
for i := 0; i < width; i++ {
698
c := getChild()
699
- if err := cur.AddNodeLinkClean(fmt.Sprint(i), c); err != nil {
699
+ if err := cur.AddNodeLink(fmt.Sprint(i), c); err != nil {
700
panic(err)
701
}
702
}
merkledag/node.go
-13
@@ -104,19 +104,6 @@ func (n *ProtoNode) AddNodeLink(name string, that ipld.Node) error {
104
return nil
105
}
106
107
-// AddNodeLinkClean adds a link to another node. without keeping a reference to
108
-// the child node
109
-func (n *ProtoNode) AddNodeLinkClean(name string, that ipld.Node) error {
110
- n.encoded = nil
111
- lnk, err := ipld.MakeLink(that)
112
- if err != nil {
113
- return err
114
- }
115
- n.AddRawLink(name, lnk)
116
-
117
- return nil
118
-}
119
-
107
// AddRawLink adds a copy of a link to this node
108
func (n *ProtoNode) AddRawLink(name string, l *ipld.Link) error {
109
n.encoded = nil
merkledag/utils/utils.go
+3
-3
@@ -75,7 +75,7 @@ func addLink(ctx context.Context, ds ipld.DAGService, root *dag.ProtoNode, child
75
// ensure no link with that name already exists
76
_ = root.RemoveNodeLink(childname) // ignore error, only option is ErrNotFound
77
78
- if err := root.AddNodeLinkClean(childname, childnd); err != nil {
78
+ if err := root.AddNodeLink(childname, childnd); err != nil {
79
return nil, err
80
}
81
@@ -127,7 +127,7 @@ func (e *Editor) insertNodeAtPath(ctx context.Context, root *dag.ProtoNode, path
127
_ = e.tmp.Remove(ctx, root.Cid())
128
129
_ = root.RemoveNodeLink(path[0])
130
- err = root.AddNodeLinkClean(path[0], ndprime)
130
+ err = root.AddNodeLink(path[0], ndprime)
131
if err != nil {
132
return nil, err
133
}
@@ -186,7 +186,7 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string)
186
e.tmp.Remove(ctx, root.Cid())
187
188
_ = root.RemoveNodeLink(path[0])
189
- err = root.AddNodeLinkClean(path[0], nnode)
189
+ err = root.AddNodeLink(path[0], nnode)
190
if err != nil {
191
return nil, err
192
}
pin/pin_test.go
+1
-1
@@ -340,7 +340,7 @@ func TestPinRecursiveFail(t *testing.T) {
340
341
a, _ := randNode()
342
b, _ := randNode()
343
- err := a.AddNodeLinkClean("child", b)
343
+ err := a.AddNodeLink("child", b)
344
if err != nil {
345
t.Fatal(err)
346
}
pin/set_test.go
+1
-1
@@ -74,7 +74,7 @@ func TestSet(t *testing.T) {
74
// weird wrapper node because loadSet expects us to pass an
75
// object pointing to multiple named sets
76
setroot := &dag.ProtoNode{}
77
- err = setroot.AddNodeLinkClean("foo", out)
77
+ err = setroot.AddNodeLink("foo", out)
78
if err != nil {
79
t.Fatal(err)
80
}
tar/format.go
+1
-1
@@ -69,7 +69,7 @@ func ImportTar(ctx context.Context, r io.Reader, ds ipld.DAGService) (*dag.Proto
69
return nil, err
70
}
71
72
- err = header.AddNodeLinkClean("data", nd)
72
+ err = header.AddNodeLink("data", nd)
73
if err != nil {
74
return nil, err
75
}
unixfs/io/dirbuilder.go
+1
-1
@@ -103,7 +103,7 @@ func (d *Directory) AddChild(ctx context.Context, name string, nd ipld.Node) err
103
if d.shard == nil {
104
if !UseHAMTSharding {
105
_ = d.dirnode.RemoveNodeLink(name)
106
- return d.dirnode.AddNodeLinkClean(name, nd)
106
+ return d.dirnode.AddNodeLink(name, nd)
107
}
108
109
err := d.switchToSharding(ctx)
unixfs/mod/dagmodifier.go
+1
-1
@@ -561,7 +561,7 @@ func dagTruncate(ctx context.Context, n ipld.Node, size uint64, ds ipld.DAGServi
561
}
562
563
nd.SetLinks(nd.Links()[:end])
564
- err = nd.AddNodeLinkClean("", modified)
564
+ err = nd.AddNodeLink("", modified)
565
if err != nil {
566
return nil, err
567
}