Commit 71ac1175 authored by Jeromy's avatar Jeromy

Address concerns in PR

parent 18ada93e
...@@ -10,8 +10,11 @@ import ( ...@@ -10,8 +10,11 @@ import (
"github.com/jbenet/go-ipfs/core" "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/importer" "github.com/jbenet/go-ipfs/importer"
"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"
uio "github.com/jbenet/go-ipfs/unixfs/io"
) )
// Error indicating the max depth has been exceded. // Error indicating the max depth has been exceded.
...@@ -87,7 +90,14 @@ func addDir(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node ...@@ -87,7 +90,14 @@ func addDir(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node
} }
func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) { func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) {
root, err := importer.NewDagFromFileWServer(fpath, n.DAG, n.Pinning) dw := uio.NewDagWriter(n.DAG, chunk.DefaultSplitter)
mp, ok := n.Pinning.(pin.ManualPinner)
if !ok {
return nil, errors.New("invalid pinner type! expected manual pinner")
}
dw.Pinner = mp
root, err := importer.ImportFileDag(fpath, dw)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
package importer package importer
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
"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"
uio "github.com/jbenet/go-ipfs/unixfs/io" uio "github.com/jbenet/go-ipfs/unixfs/io"
"github.com/jbenet/go-ipfs/util" "github.com/jbenet/go-ipfs/util"
...@@ -76,7 +74,7 @@ func NewDagFromFile(fpath string) (*dag.Node, error) { ...@@ -76,7 +74,7 @@ func NewDagFromFile(fpath string) (*dag.Node, error) {
return NewDagFromReader(f) return NewDagFromReader(f)
} }
func NewDagFromFileWServer(fpath string, dserv dag.DAGService, p pin.Pinner) (*dag.Node, error) { func ImportFileDag(fpath string, dw *uio.DagWriter) (*dag.Node, error) {
stat, err := os.Stat(fpath) stat, err := os.Stat(fpath)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -92,17 +90,10 @@ func NewDagFromFileWServer(fpath string, dserv dag.DAGService, p pin.Pinner) (*d ...@@ -92,17 +90,10 @@ func NewDagFromFileWServer(fpath string, dserv dag.DAGService, p pin.Pinner) (*d
} }
defer f.Close() defer f.Close()
return NewDagFromReaderWServer(f, dserv, p) return ImportReaderDag(f, dw)
} }
func NewDagFromReaderWServer(r io.Reader, dserv dag.DAGService, p pin.Pinner) (*dag.Node, error) { func ImportReaderDag(r io.Reader, dw *uio.DagWriter) (*dag.Node, error) {
dw := uio.NewDagWriter(dserv, chunk.DefaultSplitter)
mp, ok := p.(pin.ManualPinner)
if !ok {
return nil, errors.New("Needed to be passed a manual pinner!")
}
dw.Pinner = mp
_, err := io.Copy(dw, r) _, err := io.Copy(dw, r)
if err != nil { if err != nil {
return nil, err return nil, err
......
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