add --name new flag when ipfs adding from stdin
License: MIT Signed-off-by: Kejie Zhang <601172892@qq.com>
Kejie Zhang committed
Aug 23, 2018 at 19:17 UTC
514891d54a37c61cbfc49c897903f399c02f8ec0
2 files changed
+9
core/commands/add.go
+4
@@ -37,6 +37,7 @@ const (
37
progressOptionName = "progress"
38
trickleOptionName = "trickle"
39
wrapOptionName = "wrap-with-directory"
40
+ wrapPathName = "name"
41
hiddenOptionName = "hidden"
42
onlyHashOptionName = "only-hash"
43
chunkerOptionName = "chunker"
@@ -116,6 +117,7 @@ You can now check what blocks have been created by:
117
cmdkit.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
118
cmdkit.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
119
cmdkit.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
120
+ cmdkit.StringOption(wrapPathName, "Assign path name when use wrap-with-directory option"),
121
cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
122
cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
123
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
@@ -181,6 +183,7 @@ You can now check what blocks have been created by:
183
hashFunStr, _ := req.Options[hashOptionName].(string)
184
inline, _ := req.Options[inlineOptionName].(bool)
185
inlineLimit, _ := req.Options[inlineLimitOptionName].(int)
186
+ wrapPathName, _ := req.Options[wrapPathName].(string)
187
188
// The arguments are subject to the following constraints.
189
//
@@ -287,6 +290,7 @@ You can now check what blocks have been created by:
290
fileAdder.Silent = silent
291
fileAdder.RawLeaves = rawblks
292
fileAdder.NoCopy = nocopy
293
+ fileAdder.WpName = wrapPathName
294
fileAdder.CidBuilder = prefix
295
296
if inline {
core/coreunix/add.go
+5
@@ -26,6 +26,7 @@ import (
26
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
27
bstore "gx/ipfs/QmcmpX42gtDv1fz24kau4wjS9hfwWj5VexWBKgGnWzsyag/go-ipfs-blockstore"
28
mfs "gx/ipfs/QmdghKsSDa2AD1kC4qYRnVYWqZecdSBRZjeXRdhMYYhafj/go-mfs"
29
+ "strings"
30
)
31
32
var log = logging.Logger("coreunix")
@@ -83,6 +84,7 @@ type Adder struct {
84
RawLeaves bool
85
Silent bool
86
Wrap bool
87
+ WpName string
88
NoCopy bool
89
Chunker string
90
root ipld.Node
@@ -470,6 +472,9 @@ func (adder *Adder) addFile(file files.File) error {
472
return err
473
}
474
475
+ if !strings.EqualFold(adder.WpName, "") && adder.Wrap {
476
+ return adder.addNode(dagnode, adder.WpName)
477
+ }
478
// patch it into the root
479
return adder.addNode(dagnode, file.FileName())
480
}