@cryptotaxi247 / kubo / commits / c9446a772

object: make objectPut return CID

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jul 31, 2017 at 19:36 UTC c9446a77203a510ab44e24b05510c6c89d3bc026
1 file changed +8 -14
core/commands/object/object.go
+8 -14
@@ -393,7 +393,7 @@ And then run:
393 defer n.Blockstore.PinLock().Unlock()
394 }
395
396 - output, err := objectPut(n, input, inputenc, datafieldenc)
396 + objectCid, err := objectPut(n, input, inputenc, datafieldenc)
397 if err != nil {
398 errType := cmds.ErrNormal
399 if err == ErrUnknownObjectEnc {
@@ -404,13 +404,7 @@ And then run:
404 }
405
406 if dopin {
407 - c, err := cid.Decode(output.Hash)
408 - if err != nil {
409 - res.SetError(err, cmds.ErrNormal)
410 - return
411 - }
412 -
413 - n.Pinning.PinWithMode(c, pin.Recursive)
407 + n.Pinning.PinWithMode(objectCid, pin.Recursive)
408 err = n.Pinning.Flush()
409 if err != nil {
410 res.SetError(err, cmds.ErrNormal)
@@ -418,15 +412,15 @@ And then run:
412 }
413 }
414
421 - res.SetOutput(output)
415 + res.SetOutput(objectCid)
416 },
417 Marshalers: cmds.MarshalerMap{
418 cmds.Text: func(res cmds.Response) (io.Reader, error) {
425 - object := res.Output().(*Object)
426 - return strings.NewReader("added " + object.Hash + "\n"), nil
419 + object := res.Output().(*cid.Cid)
420 + return strings.NewReader("added " + object.String() + "\n"), nil
421 },
422 },
429 - Type: Object{},
423 + Type: cid.Cid{},
424 }
425
426 var ObjectNewCmd = &cmds.Command{
@@ -495,7 +489,7 @@ func nodeFromTemplate(template string) (*dag.ProtoNode, error) {
489 var ErrEmptyNode = errors.New("no data or links in this node")
490
491 // objectPut takes a format option, serializes bytes from stdin and updates the dag with that data
498 -func objectPut(n *core.IpfsNode, input io.Reader, encoding string, dataFieldEncoding string) (*Object, error) {
492 +func objectPut(n *core.IpfsNode, input io.Reader, encoding string, dataFieldEncoding string) (*cid.Cid, error) {
493
494 data, err := ioutil.ReadAll(io.LimitReader(input, inputLimit+10))
495 if err != nil {
@@ -560,7 +554,7 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string, dataFieldEnco
554 return nil, err
555 }
556
563 - return getOutput(dagnode)
557 + return dagnode.Cid(), nil
558 }
559
560 // ErrUnknownObjectEnc is returned if a invalid encoding is supplied