@cryptotaxi247 / kubo / commits / 7f89e09d1

fix determination of 'root' node in dag put

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jul 16, 2017 at 03:14 UTC 7f89e09d1e92f7f990fd5310f2940a55957cea91
1 file changed +9 -6
core/commands/dag/dag.go
+9 -6
@@ -82,25 +82,28 @@ into an object of the specified format.
82 res.SetError(err, cmds.ErrNormal)
83 return
84 }
85 + if len(nds) == 0 {
86 + res.SetError(fmt.Errorf("no node returned from ParseInputs"), cmds.ErrNormal)
87 + return
88 + }
89
86 - var c *cid.Cid
90 b := n.DAG.Batch()
91 for _, nd := range nds {
89 - cid, err := b.Add(nd)
92 + _, err := b.Add(nd)
93 if err != nil {
94 res.SetError(err, cmds.ErrNormal)
95 return
96 }
94 -
95 - c = cid
97 }
98 +
99 if err := b.Commit(); err != nil {
100 res.SetError(err, cmds.ErrNormal)
101 return
102 }
103
104 + root := nds[0].Cid()
105 if dopin {
103 - n.Pinning.PinWithMode(c, pin.Recursive)
106 + n.Pinning.PinWithMode(root, pin.Recursive)
107
108 err := n.Pinning.Flush()
109 if err != nil {
@@ -109,7 +112,7 @@ into an object of the specified format.
112 }
113 }
114
112 - res.SetOutput(&OutputObject{Cid: c})
115 + res.SetOutput(&OutputObject{Cid: root})
116 },
117 Type: OutputObject{},
118 Marshalers: cmds.MarshalerMap{