Skip to content

Commit

Permalink
Address concerns in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Oct 30, 2014
1 parent 18ada93 commit 71ac117
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 11 additions & 1 deletion core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (

"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/importer"
"github.com/jbenet/go-ipfs/importer/chunk"
dag "github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/pin"
ft "github.com/jbenet/go-ipfs/unixfs"
uio "github.com/jbenet/go-ipfs/unixfs/io"
)

// Error indicating the max depth has been exceded.
Expand Down Expand Up @@ -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) {
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 {
return nil, err
}
Expand Down
15 changes: 3 additions & 12 deletions importer/importer.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package importer

import (
"errors"
"fmt"
"io"
"os"

"github.com/jbenet/go-ipfs/importer/chunk"
dag "github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/pin"
ft "github.com/jbenet/go-ipfs/unixfs"
uio "github.com/jbenet/go-ipfs/unixfs/io"
"github.com/jbenet/go-ipfs/util"
Expand Down Expand Up @@ -76,7 +74,7 @@ func NewDagFromFile(fpath string) (*dag.Node, error) {
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)
if err != nil {
return nil, err
Expand All @@ -92,17 +90,10 @@ func NewDagFromFileWServer(fpath string, dserv dag.DAGService, p pin.Pinner) (*d
}
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) {
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
func ImportReaderDag(r io.Reader, dw *uio.DagWriter) (*dag.Node, error) {
_, err := io.Copy(dw, r)
if err != nil {
return nil, err
Expand Down

0 comments on commit 71ac117

Please sign in to comment.