diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index 1f4f620499cb..13ccd5eddb63 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -110,7 +110,7 @@ into an object of the specified format. } for _, nd := range nds { - err := b.Add(nd) + err := b.Add(req.Context, nd) if err != nil { return err } diff --git a/core/coreunix/add.go b/core/coreunix/add.go index fd71ab8a136e..2c7afb184106 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -49,11 +49,14 @@ type Object struct { // NewAdder Returns a new Adder used for a file add operation. func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds ipld.DAGService) (*Adder, error) { + bufferedDS := ipld.NewBufferedDAG(ctx, ds) + return &Adder{ ctx: ctx, pinning: p, blockstore: bs, dagService: ds, + bufferedDS: bufferedDS, Progress: false, Hidden: true, Pin: true, @@ -69,6 +72,7 @@ type Adder struct { pinning pin.Pinner blockstore bstore.GCBlockstore dagService ipld.DAGService + bufferedDS *ipld.BufferedDAG Out chan<- interface{} Progress bool Hidden bool @@ -114,8 +118,11 @@ func (adder *Adder) add(reader io.Reader) (ipld.Node, error) { return nil, err } + // Make sure all added nodes are written when done. + defer adder.bufferedDS.Commit() + params := ihelper.DagBuilderParams{ - Dagserv: adder.dagService, + Dagserv: adder.bufferedDS, RawLeaves: adder.RawLeaves, Maxlinks: ihelper.DefaultLinksPerBlock, NoCopy: adder.NoCopy,