Commit b22eae6b authored by Jeromy's avatar Jeromy

set data and links nil if not present

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 6ccb17a4
......@@ -50,7 +50,9 @@ func (n *Node) Marshal() ([]byte, error) {
func (n *Node) getPBNode() *pb.PBNode {
pbn := &pb.PBNode{}
pbn.Links = make([]*pb.PBLink, len(n.Links))
if len(n.Links) > 0 {
pbn.Links = make([]*pb.PBLink, len(n.Links))
}
sort.Stable(LinkSlice(n.Links)) // keep links sorted
for i, l := range n.Links {
......@@ -60,7 +62,9 @@ func (n *Node) getPBNode() *pb.PBNode {
pbn.Links[i].Hash = []byte(l.Hash)
}
pbn.Data = n.Data
if len(n.Data) > 0 {
pbn.Data = n.Data
}
return pbn
}
......
......@@ -176,11 +176,15 @@ func (n *Node) GetLinkedNode(ctx context.Context, ds DAGService, name string) (*
// NOTE: does not make copies of Node objects in the links.
func (n *Node) Copy() *Node {
nnode := new(Node)
nnode.Data = make([]byte, len(n.Data))
copy(nnode.Data, n.Data)
if len(n.Data) > 0 {
nnode.Data = make([]byte, len(n.Data))
copy(nnode.Data, n.Data)
}
nnode.Links = make([]*Link, len(n.Links))
copy(nnode.Links, n.Links)
if len(n.Links) > 0 {
nnode.Links = make([]*Link, len(n.Links))
copy(nnode.Links, n.Links)
}
return nnode
}
......
......@@ -85,8 +85,8 @@ func TestInsertNode(t *testing.T) {
t.Fatal(err)
}
if k.B58String() != "QmThorWojP6YzLJwDukxiYCoKQSwyrMCvdt4WZ6rPm221t" {
t.Fatal("output was different than expected")
if k.B58String() != "QmZ8yeT9uD6ouJPNAYt62XffYuXBT6b4mP4obRSE9cJrSt" {
t.Fatal("output was different than expected: ", k)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment