Commit c322a4eb authored by W. Trevor King's avatar W. Trevor King

core/commands/add: Change add() to only accept a single reader

The change to an array of readers comes from e096060b
(refactor(core/commands2/add) split loop, 2014-11-06), where it's used
to setup readers for each path in the argument list.  However, since
6faeee83 (cmds2/add: temp fix for -r. horrible hack, 2014-11-11) the
argument looping moved outside of add() and into Run(), so we can drop
the multiple-reader support from add().

Adding a file can create multiple nodes (e.g. the splitter can chunk
the file into several blocks), but:

1. we were only appending a single node per reader to our returned
   list, and
2. we are only using the final node in that returned list,

so this commit also adjusts add() to return a single node reference
instead on an array of nodes.
parent b1adeef8
......@@ -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) {
......
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