Skip to content

Commit

Permalink
Merge pull request #1127 from wking/add-single-reader
Browse files Browse the repository at this point in the history
core/commands/add: Change add() to only accept a single reader
  • Loading branch information
jbenet committed Apr 27, 2015
2 parents c9bf470 + 641c20b commit 196c6aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
23 changes: 9 additions & 14 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,18 @@ remains to be implemented.
Type: AddedObject{},
}

func add(n *core.IpfsNode, readers []io.Reader) ([]*dag.Node, error) {
dagnodes := make([]*dag.Node, 0)

for _, reader := range readers {
node, err := importer.BuildDagFromReader(reader, n.DAG, nil, chunk.DefaultSplitter)
if err != nil {
return nil, err
}
dagnodes = append(dagnodes, node)
func add(n *core.IpfsNode, reader io.Reader) (*dag.Node, error) {
node, err := importer.BuildDagFromReader(reader, n.DAG, nil, chunk.DefaultSplitter)
if err != nil {
return nil, err
}

err := n.Pinning.Flush()
err = n.Pinning.Flush()
if err != nil {
return nil, err
}

return dagnodes, nil
return node, nil
}

func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress bool, wrap bool) (*dag.Node, error) {
Expand All @@ -256,16 +251,16 @@ func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress b
return dagnode, nil
}

dns, err := add(n, []io.Reader{reader})
dagnode, err := add(n, reader)
if err != nil {
return nil, err
}

log.Infof("adding file: %s", file.FileName())
if err := outputDagnode(out, file.FileName(), dns[len(dns)-1]); err != nil {
if err := outputDagnode(out, file.FileName(), dagnode); err != nil {
return nil, err
}
return dns[len(dns)-1], nil // last dag node is the file.
return dagnode, nil
}

func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress bool) (*dag.Node, error) {
Expand Down
23 changes: 11 additions & 12 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,23 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, *merkle
return gopath.Join(k.String(), filename), dagnode, nil
}

func add(n *core.IpfsNode, readers []io.Reader) ([]*merkledag.Node, error) {
func add(n *core.IpfsNode, reader io.Reader) (*merkledag.Node, error) {
mp, ok := n.Pinning.(pin.ManualPinner)
if !ok {
return nil, errors.New("invalid pinner type! expected manual pinner")
}
dagnodes := make([]*merkledag.Node, 0)
for _, reader := range readers {
node, err := importer.BuildDagFromReader(reader, n.DAG, mp, chunk.DefaultSplitter)
if err != nil {
return nil, err
}
dagnodes = append(dagnodes, node)

node, err := importer.BuildDagFromReader(reader, n.DAG, mp, chunk.DefaultSplitter)
if err != nil {
return nil, err
}
err := n.Pinning.Flush()

err = n.Pinning.Flush()
if err != nil {
return nil, err
}
return dagnodes, nil

return node, nil
}

func addNode(n *core.IpfsNode, node *merkledag.Node) error {
Expand All @@ -125,12 +124,12 @@ func addFile(n *core.IpfsNode, file files.File) (*merkledag.Node, error) {
return addDir(n, file)
}

dns, err := add(n, []io.Reader{file})
dagnode, err := add(n, file)
if err != nil {
return nil, err
}

return dns[len(dns)-1], nil // last dag node is the file.
return dagnode, nil
}

func addDir(n *core.IpfsNode, dir files.File) (*merkledag.Node, error) {
Expand Down

0 comments on commit 196c6aa

Please sign in to comment.