Commit 196c6aa4 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #1127 from wking/add-single-reader

core/commands/add: Change add() to only accept a single reader
parents c9bf4703 641c20b9
......@@ -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) {
......@@ -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) {
......
......@@ -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 {
......@@ -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) {
......
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