Commit bdef3a1f authored by Jeromy's avatar Jeromy

rewrite add command to use dagwriter, moved a pinner into the dagwriter for inline pinning

parent b73ce6e1
...@@ -3,6 +3,7 @@ package io ...@@ -3,6 +3,7 @@ package io
import ( import (
"github.com/jbenet/go-ipfs/importer/chunk" "github.com/jbenet/go-ipfs/importer/chunk"
dag "github.com/jbenet/go-ipfs/merkledag" dag "github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/pin"
ft "github.com/jbenet/go-ipfs/unixfs" ft "github.com/jbenet/go-ipfs/unixfs"
"github.com/jbenet/go-ipfs/util" "github.com/jbenet/go-ipfs/util"
) )
...@@ -17,6 +18,7 @@ type DagWriter struct { ...@@ -17,6 +18,7 @@ type DagWriter struct {
done chan struct{} done chan struct{}
splitter chunk.BlockSplitter splitter chunk.BlockSplitter
seterr error seterr error
Pinner pin.ManualPinner
} }
func NewDagWriter(ds dag.DAGService, splitter chunk.BlockSplitter) *DagWriter { func NewDagWriter(ds dag.DAGService, splitter chunk.BlockSplitter) *DagWriter {
...@@ -48,7 +50,10 @@ func (dw *DagWriter) startSplitter() { ...@@ -48,7 +50,10 @@ func (dw *DagWriter) startSplitter() {
// Store the block size in the root node // Store the block size in the root node
mbf.AddBlockSize(uint64(len(blkData))) mbf.AddBlockSize(uint64(len(blkData)))
node := &dag.Node{Data: ft.WrapData(blkData)} node := &dag.Node{Data: ft.WrapData(blkData)}
_, err := dw.dagserv.Add(node) nk, err := dw.dagserv.Add(node)
if dw.Pinner != nil {
dw.Pinner.PinWithMode(nk, pin.Indirect)
}
if err != nil { if err != nil {
dw.seterr = err dw.seterr = err
log.Critical("Got error adding created node to dagservice: %s", err) log.Critical("Got error adding created node to dagservice: %s", err)
...@@ -75,12 +80,15 @@ func (dw *DagWriter) startSplitter() { ...@@ -75,12 +80,15 @@ func (dw *DagWriter) startSplitter() {
root.Data = data root.Data = data
// Add root node to the dagservice // Add root node to the dagservice
_, err = dw.dagserv.Add(root) rootk, err := dw.dagserv.Add(root)
if err != nil { if err != nil {
dw.seterr = err dw.seterr = err
log.Critical("Got error adding created node to dagservice: %s", err) log.Critical("Got error adding created node to dagservice: %s", err)
return return
} }
if dw.Pinner != nil {
dw.Pinner.PinWithMode(rootk, pin.Recursive)
}
dw.node = root dw.node = root
dw.done <- struct{}{} dw.done <- struct{}{}
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment