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>
This commit is contained in:
Lucas Molas 2018-04-16 17:49:54 -03:00
parent 0cb22ccf35
commit e047b58a33
10 changed files with 17 additions and 30 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)

View File

@ -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
}