提交 514891d5 作者: Kejie Zhang

add --name new flag when ipfs adding from stdin

License: MIT
Signed-off-by: 's avatarKejie Zhang <601172892@qq.com>
上级 9a21a8cb
...@@ -37,6 +37,7 @@ const ( ...@@ -37,6 +37,7 @@ const (
progressOptionName = "progress" progressOptionName = "progress"
trickleOptionName = "trickle" trickleOptionName = "trickle"
wrapOptionName = "wrap-with-directory" wrapOptionName = "wrap-with-directory"
wrapPathName = "name"
hiddenOptionName = "hidden" hiddenOptionName = "hidden"
onlyHashOptionName = "only-hash" onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker" chunkerOptionName = "chunker"
...@@ -116,6 +117,7 @@ You can now check what blocks have been created by: ...@@ -116,6 +117,7 @@ You can now check what blocks have been created by:
cmdkit.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."), cmdkit.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmdkit.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."), cmdkit.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
cmdkit.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."), cmdkit.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
cmdkit.StringOption(wrapPathName, "Assign path name when use wrap-with-directory option"),
cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."), cmdkit.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"), cmdkit.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]").WithDefault("size-262144"),
cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true), cmdkit.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
...@@ -181,6 +183,7 @@ You can now check what blocks have been created by: ...@@ -181,6 +183,7 @@ You can now check what blocks have been created by:
hashFunStr, _ := req.Options[hashOptionName].(string) hashFunStr, _ := req.Options[hashOptionName].(string)
inline, _ := req.Options[inlineOptionName].(bool) inline, _ := req.Options[inlineOptionName].(bool)
inlineLimit, _ := req.Options[inlineLimitOptionName].(int) inlineLimit, _ := req.Options[inlineLimitOptionName].(int)
wrapPathName, _ := req.Options[wrapPathName].(string)
// The arguments are subject to the following constraints. // The arguments are subject to the following constraints.
// //
...@@ -287,6 +290,7 @@ You can now check what blocks have been created by: ...@@ -287,6 +290,7 @@ You can now check what blocks have been created by:
fileAdder.Silent = silent fileAdder.Silent = silent
fileAdder.RawLeaves = rawblks fileAdder.RawLeaves = rawblks
fileAdder.NoCopy = nocopy fileAdder.NoCopy = nocopy
fileAdder.WpName = wrapPathName
fileAdder.CidBuilder = prefix fileAdder.CidBuilder = prefix
if inline { if inline {
......
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid" cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
bstore "gx/ipfs/QmcmpX42gtDv1fz24kau4wjS9hfwWj5VexWBKgGnWzsyag/go-ipfs-blockstore" bstore "gx/ipfs/QmcmpX42gtDv1fz24kau4wjS9hfwWj5VexWBKgGnWzsyag/go-ipfs-blockstore"
mfs "gx/ipfs/QmdghKsSDa2AD1kC4qYRnVYWqZecdSBRZjeXRdhMYYhafj/go-mfs" mfs "gx/ipfs/QmdghKsSDa2AD1kC4qYRnVYWqZecdSBRZjeXRdhMYYhafj/go-mfs"
"strings"
) )
var log = logging.Logger("coreunix") var log = logging.Logger("coreunix")
...@@ -83,6 +84,7 @@ type Adder struct { ...@@ -83,6 +84,7 @@ type Adder struct {
RawLeaves bool RawLeaves bool
Silent bool Silent bool
Wrap bool Wrap bool
WpName string
NoCopy bool NoCopy bool
Chunker string Chunker string
root ipld.Node root ipld.Node
...@@ -470,6 +472,9 @@ func (adder *Adder) addFile(file files.File) error { ...@@ -470,6 +472,9 @@ func (adder *Adder) addFile(file files.File) error {
return err return err
} }
if !strings.EqualFold(adder.WpName, "") && adder.Wrap {
return adder.addNode(dagnode, adder.WpName)
}
// patch it into the root // patch it into the root
return adder.addNode(dagnode, file.FileName()) return adder.addNode(dagnode, file.FileName())
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论