Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dbb9ec4

Browse files
committedNov 3, 2015
set data and links nil if not present
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent e90bd93 commit dbb9ec4

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed
 

‎merkledag/coding.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ func (n *Node) Marshal() ([]byte, error) {
5050

5151
func (n *Node) getPBNode() *pb.PBNode {
5252
pbn := &pb.PBNode{}
53-
pbn.Links = make([]*pb.PBLink, len(n.Links))
53+
if len(n.Links) > 0 {
54+
pbn.Links = make([]*pb.PBLink, len(n.Links))
55+
}
5456

5557
sort.Stable(LinkSlice(n.Links)) // keep links sorted
5658
for i, l := range n.Links {
@@ -60,7 +62,9 @@ func (n *Node) getPBNode() *pb.PBNode {
6062
pbn.Links[i].Hash = []byte(l.Hash)
6163
}
6264

63-
pbn.Data = n.Data
65+
if len(n.Data) > 0 {
66+
pbn.Data = n.Data
67+
}
6468
return pbn
6569
}
6670

‎merkledag/node.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@ func (n *Node) GetLinkedNode(ctx context.Context, ds DAGService, name string) (*
176176
// NOTE: does not make copies of Node objects in the links.
177177
func (n *Node) Copy() *Node {
178178
nnode := new(Node)
179-
nnode.Data = make([]byte, len(n.Data))
180-
copy(nnode.Data, n.Data)
179+
if len(n.Data) > 0 {
180+
nnode.Data = make([]byte, len(n.Data))
181+
copy(nnode.Data, n.Data)
182+
}
181183

182-
nnode.Links = make([]*Link, len(n.Links))
183-
copy(nnode.Links, n.Links)
184+
if len(n.Links) > 0 {
185+
nnode.Links = make([]*Link, len(n.Links))
186+
copy(nnode.Links, n.Links)
187+
}
184188
return nnode
185189
}
186190

‎test/sharness/t0051-object.sh

+6
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ test_object_cmd() {
234234

235235
test_patch_create_path $EMPTY a/b/b/b/b $FILE
236236

237+
test_expect_success "can create blank object" '
238+
BLANK=$(ipfs object new)
239+
'
240+
241+
test_patch_create_path $BLANK a $FILE
242+
237243
test_expect_success "create bad path fails" '
238244
test_must_fail ipfs object patch --create $EMPTY add-link / $FILE
239245
'

0 commit comments

Comments
 (0)
Please sign in to comment.