Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object-patch: Support linking to non-dagpb objects #4460

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,7 @@ to a file containing 'bar', and returns the hash of the new object.
return
}

chpb, ok := childnd.(*dag.ProtoNode)
if !ok {
res.SetError(dag.ErrNotProtobuf, cmdkit.ErrNormal)
return
}

err = e.InsertNodeAtPath(req.Context(), npath, chpb, createfunc)
err = e.InsertNodeAtPath(req.Context(), npath, childnd, createfunc)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
9 changes: 2 additions & 7 deletions merkledag/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (e *Editor) Finalize(ds dag.DAGService) (*dag.ProtoNode, error) {
return nd, err
}

func copyDag(nd *dag.ProtoNode, from, to dag.DAGService) error {
func copyDag(nd node.Node, from, to dag.DAGService) error {
_, err := to.Add(nd)
if err != nil {
return err
Expand All @@ -211,12 +211,7 @@ func copyDag(nd *dag.ProtoNode, from, to dag.DAGService) error {
return err
}

childpb, ok := child.(*dag.ProtoNode)
if !ok {
return dag.ErrNotProtobuf
}

err = copyDag(childpb, from, to)
err = copyDag(child, from, to)
if err != nil {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ test_object_cmd() {
ipfs object stat /ipfs/$N3/foo/baz > /dev/null
'

test_expect_success "'ipfs object patch add-link' allow linking IPLD objects" '
EMPTY_DIR=$(ipfs object new unixfs-dir) &&
OBJ=$(echo "123" | ipfs dag put) &&
N1=$(ipfs object patch $EMPTY_DIR add-link foo $OBJ) &&

ipfs object stat /ipfs/$N1 > /dev/null &&
ipfs resolve /ipfs/$N1/foo > actual &&
echo /ipfs/$OBJ > expected &&

test_cmp expected actual
'



test_expect_success "object patch creation looks right" '
echo "QmPc73aWK9dgFBXe86P4PvQizHo9e5Qt7n7DAMXWuigFuG" > hash_exp &&
echo $N3 > hash_actual &&
Expand Down