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 1 commit
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
5 changes: 3 additions & 2 deletions merkledag/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ func copyDag(nd *dag.ProtoNode, from, to dag.DAGService) error {
}

childpb, ok := child.(*dag.ProtoNode)
if !ok {
return dag.ErrNotProtobuf
if !ok { // leaf node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit risky to do this way. Lets switch on the type, and then explicitly handle the ProtoNode and RawNodes. Then for everything else we can error out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not allow linking to other types? I actually need this to link to git commits, it works well for my usecase (ipld git helper). (note that it's already possible to do this with dag commands)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue isnt that we don't want to allow linking, but that this operation is supposed to recursively copy a graph from one dagservice to another.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magik6k we can change the first argument of this function to accept a node.Node, then skip this check entirely

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_, err := to.Add(nd)
return err
}

err = copyDag(childpb, from, to)
Expand Down
7 changes: 7 additions & 0 deletions test/sharness/t0051-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ 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 $N1 > /dev/null
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also test resolving the link, i.e. $N1/foo

'

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