Skip to content

Commit

Permalink
move mem-dag construction to its own function, and actually call Writ…
Browse files Browse the repository at this point in the history
…eOutputTo

License: MIT
Signed-off-by: Jeromy <[email protected]>
  • Loading branch information
whyrusleeping committed Sep 4, 2015
1 parent 6131a27 commit 991cd4c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
3 changes: 3 additions & 0 deletions blockservice/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block,
log.Debug("Blockservice: Searching bitswap.")
blk, err := s.Exchange.GetBlock(ctx, k)
if err != nil {
if err == blockstore.ErrNotFound {
return nil, ErrNotFound
}
return nil, err
}
return blk, nil
Expand Down
30 changes: 19 additions & 11 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ remains to be implemented.
hidden, _, _ := req.Option(hiddenOptionName).Bool()
chunker, _, _ := req.Option(chunkerOptionName).String()

e := dagutils.NewDagEditor(n.DAG, newDirNode())
e := dagutils.NewDagEditor(NewMemoryDagService(), newDirNode())
if hash {
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
//TODO: need this to be true or all files
Expand All @@ -120,16 +120,6 @@ remains to be implemented.
return
}
n = nilnode

// build mem-datastore for editor's intermediary nodes
bs := bstore.NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
bsrv, err := bserv.New(bs, offline.Exchange(bs))
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
memds := dag.NewDAGService(bsrv)
e = dagutils.NewDagEditor(memds, newDirNode())
}

outChan := make(chan interface{}, 8)
Expand Down Expand Up @@ -182,6 +172,15 @@ remains to be implemented.
return err
}

if !hash {
// copy intermediary nodes from editor to our actual dagservice
err := e.WriteOutputTo(n.DAG)
if err != nil {
log.Error("WRITE OUT: ", err)
return err
}
}

rootnd, err := fileAdder.RootNode()
if err != nil {
return err
Expand All @@ -196,6 +195,7 @@ remains to be implemented.
res.SetError(err, cmds.ErrNormal)
return
}

}()
},
PostRun: func(req cmds.Request, res cmds.Response) {
Expand Down Expand Up @@ -284,6 +284,13 @@ remains to be implemented.
Type: AddedObject{},
}

func NewMemoryDagService() dag.DAGService {
// build mem-datastore for editor's intermediary nodes
bs := bstore.NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
bsrv := bserv.New(bs, offline.Exchange(bs))
return dag.NewDAGService(bsrv)
}

// Internal structure for holding the switches passed to the `add` call
type adder struct {
ctx cxt.Context
Expand Down Expand Up @@ -335,6 +342,7 @@ func (params *adder) RootNode() (*dag.Node, error) {
if !params.wrap && len(r.Links) == 1 {
var err error
r, err = r.Links[0].GetNode(params.ctx, params.editor.GetDagService())
log.Error("ERR: ", err)
// no need to output, as we've already done so.
return r, err
}
Expand Down
3 changes: 3 additions & 0 deletions merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {

b, err := n.Blocks.GetBlock(ctx, k)
if err != nil {
if err == bserv.ErrNotFound {
return nil, ErrNotFound
}
return nil, err
}

Expand Down
12 changes: 10 additions & 2 deletions merkledag/utils/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha
for _, c := range cs {
switch c.Type {
case Add:
err := e.InsertNodeAtPath(ctx, c.Path, c.After, nil)
child, err := ds.Get(ctx, c.After)
if err != nil {
return nil, err
}
err = e.InsertNodeAtPath(ctx, c.Path, child, nil)
if err != nil {
return nil, err
}
Expand All @@ -57,7 +61,11 @@ func ApplyChange(ctx context.Context, ds dag.DAGService, nd *dag.Node, cs []*Cha
if err != nil {
return nil, err
}
err = e.InsertNodeAtPath(ctx, c.Path, c.After, nil)
child, err := ds.Get(ctx, c.After)
if err != nil {
return nil, err
}
err = e.InsertNodeAtPath(ctx, c.Path, child, nil)
if err != nil {
return nil, err
}
Expand Down
14 changes: 0 additions & 14 deletions util/sadhack/godep.go

This file was deleted.

0 comments on commit 991cd4c

Please sign in to comment.