Skip to content

Commit

Permalink
dag: fix pin lock usage
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Sep 20, 2017
1 parent eb7da51 commit 03cf65b
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
u "gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util"
mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
"reflect"
)

var DagCmd = &cmds.Command{
Expand Down Expand Up @@ -93,10 +92,6 @@ into an object of the specified format.
}
}

if dopin {
defer n.Blockstore.PinLock().Unlock()
}

outChan := make(chan interface{}, 8)
res.SetOutput((<-chan interface{})(outChan))

Expand All @@ -118,29 +113,37 @@ into an object of the specified format.
return fmt.Errorf("no node returned from ParseInputs")
}

b := n.DAG.Batch()
for _, nd := range nds {
_, err := b.Add(nd)
if err != nil {
return err
var cid *cid.Cid
err = func() error {
if dopin {
defer n.Blockstore.PinLock().Unlock()
}
}

if err := b.Commit(); err != nil {
return err
}

root := nds[0].Cid()
if dopin {
n.Pinning.PinWithMode(root, pin.Recursive)
b := n.DAG.Batch()
for _, nd := range nds {
_, err := b.Add(nd)
if err != nil {
return err
}
}

err := n.Pinning.Flush()
if err != nil {
if err := b.Commit(); err != nil {
return err
}
}

outChan <- &OutputObject{Cid: root}
cid = nds[0].Cid()
if dopin {
n.Pinning.PinWithMode(cid, pin.Recursive)

err := n.Pinning.Flush()
if err != nil {
return err
}
}
return nil
}()

outChan <- &OutputObject{Cid: cid}
}

return nil
Expand All @@ -159,7 +162,6 @@ into an object of the specified format.
cmds.Text: func(res cmds.Response) (io.Reader, error) {
outChan, ok := res.Output().(<-chan interface{})
if !ok {
fmt.Println(reflect.TypeOf(res.Output()))
return nil, u.ErrCast()
}

Expand Down

0 comments on commit 03cf65b

Please sign in to comment.