From 7f89e09d1e92f7f990fd5310f2940a55957cea91 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 16 Jul 2017 03:14:33 -0700 Subject: [PATCH] fix determination of 'root' node in dag put License: MIT Signed-off-by: Jeromy --- core/commands/dag/dag.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index f61f3a1e564..09db4c13c4d 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -82,25 +82,28 @@ into an object of the specified format. res.SetError(err, cmds.ErrNormal) return } + if len(nds) == 0 { + res.SetError(fmt.Errorf("no node returned from ParseInputs"), cmds.ErrNormal) + return + } - var c *cid.Cid b := n.DAG.Batch() for _, nd := range nds { - cid, err := b.Add(nd) + _, err := b.Add(nd) if err != nil { res.SetError(err, cmds.ErrNormal) return } - - c = cid } + if err := b.Commit(); err != nil { res.SetError(err, cmds.ErrNormal) return } + root := nds[0].Cid() if dopin { - n.Pinning.PinWithMode(c, pin.Recursive) + n.Pinning.PinWithMode(root, pin.Recursive) err := n.Pinning.Flush() if err != nil { @@ -109,7 +112,7 @@ into an object of the specified format. } } - res.SetOutput(&OutputObject{Cid: c}) + res.SetOutput(&OutputObject{Cid: root}) }, Type: OutputObject{}, Marshalers: cmds.MarshalerMap{