mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
Merge pull request #1379 from dylanPowers/use-trickle-dag
Wired up the trickle dag flag for the add command
This commit is contained in:
@ -28,6 +28,7 @@ const progressReaderIncrement = 1024 * 256
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
progressOptionName = "progress"
|
progressOptionName = "progress"
|
||||||
|
trickleOptionName = "trickle"
|
||||||
wrapOptionName = "wrap-with-directory"
|
wrapOptionName = "wrap-with-directory"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ remains to be implemented.
|
|||||||
cmds.BoolOption("quiet", "q", "Write minimal output"),
|
cmds.BoolOption("quiet", "q", "Write minimal output"),
|
||||||
cmds.BoolOption(progressOptionName, "p", "Stream progress data"),
|
cmds.BoolOption(progressOptionName, "p", "Stream progress data"),
|
||||||
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
|
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
|
||||||
cmds.BoolOption("t", "trickle", "Use trickle-dag format for dag generation"),
|
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation"),
|
||||||
},
|
},
|
||||||
PreRun: func(req cmds.Request) error {
|
PreRun: func(req cmds.Request) error {
|
||||||
if quiet, _, _ := req.Option("quiet").Bool(); quiet {
|
if quiet, _, _ := req.Option("quiet").Bool(); quiet {
|
||||||
@ -89,6 +90,7 @@ remains to be implemented.
|
|||||||
}
|
}
|
||||||
|
|
||||||
progress, _, _ := req.Option(progressOptionName).Bool()
|
progress, _, _ := req.Option(progressOptionName).Bool()
|
||||||
|
trickle, _, _ := req.Option(trickleOptionName).Bool()
|
||||||
wrap, _, _ := req.Option(wrapOptionName).Bool()
|
wrap, _, _ := req.Option(wrapOptionName).Bool()
|
||||||
|
|
||||||
outChan := make(chan interface{}, 8)
|
outChan := make(chan interface{}, 8)
|
||||||
@ -107,7 +109,7 @@ remains to be implemented.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rootnd, err := addFile(n, file, outChan, progress, wrap)
|
rootnd, err := addFile(n, file, outChan, progress, wrap, trickle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -217,13 +219,25 @@ remains to be implemented.
|
|||||||
Type: AddedObject{},
|
Type: AddedObject{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(n *core.IpfsNode, reader io.Reader) (*dag.Node, error) {
|
func add(n *core.IpfsNode, reader io.Reader, useTrickle bool) (*dag.Node, error) {
|
||||||
node, err := importer.BuildDagFromReader(
|
var node *dag.Node
|
||||||
reader,
|
var err error
|
||||||
n.DAG,
|
if useTrickle {
|
||||||
chunk.DefaultSplitter,
|
node, err = importer.BuildTrickleDagFromReader(
|
||||||
importer.PinIndirectCB(n.Pinning.GetManual()),
|
reader,
|
||||||
)
|
n.DAG,
|
||||||
|
chunk.DefaultSplitter,
|
||||||
|
importer.PinIndirectCB(n.Pinning.GetManual()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
node, err = importer.BuildDagFromReader(
|
||||||
|
reader,
|
||||||
|
n.DAG,
|
||||||
|
chunk.DefaultSplitter,
|
||||||
|
importer.PinIndirectCB(n.Pinning.GetManual()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -231,9 +245,9 @@ func add(n *core.IpfsNode, reader io.Reader) (*dag.Node, error) {
|
|||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress bool, wrap bool) (*dag.Node, error) {
|
func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress bool, wrap bool, useTrickle bool) (*dag.Node, error) {
|
||||||
if file.IsDirectory() {
|
if file.IsDirectory() {
|
||||||
return addDir(n, file, out, progress)
|
return addDir(n, file, out, progress, useTrickle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the progress flag was specified, wrap the file so that we can send
|
// if the progress flag was specified, wrap the file so that we can send
|
||||||
@ -255,7 +269,7 @@ func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress b
|
|||||||
return dagnode, nil
|
return dagnode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dagnode, err := add(n, reader)
|
dagnode, err := add(n, reader, useTrickle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -267,7 +281,7 @@ func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress b
|
|||||||
return dagnode, nil
|
return dagnode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress bool) (*dag.Node, error) {
|
func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress bool, useTrickle bool) (*dag.Node, error) {
|
||||||
log.Infof("adding directory: %s", dir.FileName())
|
log.Infof("adding directory: %s", dir.FileName())
|
||||||
|
|
||||||
tree := &dag.Node{Data: ft.FolderPBData()}
|
tree := &dag.Node{Data: ft.FolderPBData()}
|
||||||
@ -281,7 +295,7 @@ func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress boo
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err := addFile(n, file, out, progress, false)
|
node, err := addFile(n, file, out, progress, false, useTrickle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user