Wired up the trickle dag flag for the add command
License: MIT Signed-off-by: Dylan Powers <dylan.kyle.powers@gmail.com>
Dylan Powers committed
Jun 16, 2015 at 15:34 UTC
600e1523e463ed684a2735b95a422bed0f8013e3
1 file changed
+28
-14
core/commands/add.go
+28
-14
@@ -28,6 +28,7 @@ const progressReaderIncrement = 1024 * 256
28
29
const (
30
progressOptionName = "progress"
31
+ trickleOptionName = "trickle"
32
wrapOptionName = "wrap-with-directory"
33
)
34
@@ -56,7 +57,7 @@ remains to be implemented.
57
cmds.BoolOption("quiet", "q", "Write minimal output"),
58
cmds.BoolOption(progressOptionName, "p", "Stream progress data"),
59
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
59
- cmds.BoolOption("t", "trickle", "Use trickle-dag format for dag generation"),
60
+ cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation"),
61
},
62
PreRun: func(req cmds.Request) error {
63
if quiet, _, _ := req.Option("quiet").Bool(); quiet {
@@ -89,6 +90,7 @@ remains to be implemented.
90
}
91
92
progress, _, _ := req.Option(progressOptionName).Bool()
93
+ trickle, _, _ := req.Option(trickleOptionName).Bool()
94
wrap, _, _ := req.Option(wrapOptionName).Bool()
95
96
outChan := make(chan interface{}, 8)
@@ -107,7 +109,7 @@ remains to be implemented.
109
return
110
}
111
110
- rootnd, err := addFile(n, file, outChan, progress, wrap)
112
+ rootnd, err := addFile(n, file, outChan, progress, wrap, trickle)
113
if err != nil {
114
res.SetError(err, cmds.ErrNormal)
115
return
@@ -217,13 +219,25 @@ remains to be implemented.
219
Type: AddedObject{},
220
}
221
220
-func add(n *core.IpfsNode, reader io.Reader) (*dag.Node, error) {
221
- node, err := importer.BuildDagFromReader(
222
- reader,
223
- n.DAG,
224
- chunk.DefaultSplitter,
225
- importer.PinIndirectCB(n.Pinning.GetManual()),
226
- )
222
+func add(n *core.IpfsNode, reader io.Reader, useTrickle bool) (*dag.Node, error) {
223
+ var node *dag.Node
224
+ var err error
225
+ if useTrickle {
226
+ node, err = importer.BuildTrickleDagFromReader(
227
+ reader,
228
+ n.DAG,
229
+ chunk.DefaultSplitter,
230
+ importer.PinIndirectCB(n.Pinning.GetManual()),
231
+ )
232
+ } else {
233
+ node, err = importer.BuildDagFromReader(
234
+ reader,
235
+ n.DAG,
236
+ chunk.DefaultSplitter,
237
+ importer.PinIndirectCB(n.Pinning.GetManual()),
238
+ )
239
+ }
240
+
241
if err != nil {
242
return nil, err
243
}
@@ -231,9 +245,9 @@ func add(n *core.IpfsNode, reader io.Reader) (*dag.Node, error) {
245
return node, nil
246
}
247
234
-func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress bool, wrap bool) (*dag.Node, error) {
248
+func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress bool, wrap bool, useTrickle bool) (*dag.Node, error) {
249
if file.IsDirectory() {
236
- return addDir(n, file, out, progress)
250
+ return addDir(n, file, out, progress, useTrickle)
251
}
252
253
// 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
269
return dagnode, nil
270
}
271
258
- dagnode, err := add(n, reader)
272
+ dagnode, err := add(n, reader, useTrickle)
273
if err != nil {
274
return nil, err
275
}
@@ -267,7 +281,7 @@ func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress b
281
return dagnode, nil
282
}
283
270
-func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress bool) (*dag.Node, error) {
284
+func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress bool, useTrickle bool) (*dag.Node, error) {
285
log.Infof("adding directory: %s", dir.FileName())
286
287
tree := &dag.Node{Data: ft.FolderPBData()}
@@ -281,7 +295,7 @@ func addDir(n *core.IpfsNode, dir files.File, out chan interface{}, progress boo
295
break
296
}
297
284
- node, err := addFile(n, file, out, progress, false)
298
+ node, err := addFile(n, file, out, progress, false, useTrickle)
299
if err != nil {
300
return nil, err
301
}