Skip to content

Commit

Permalink
add --name new flag when ipfs adding from stdin
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kejie Zhang <601172892@qq.com>
  • Loading branch information
kjzz committed Aug 31, 2018
1 parent 9a21a8c commit 514891d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
progressOptionName = "progress"
trickleOptionName = "trickle"
wrapOptionName = "wrap-with-directory"
wrapPathName = "name"
hiddenOptionName = "hidden"
onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker"
Expand Down Expand Up @@ -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(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
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.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),
Expand Down Expand Up @@ -181,6 +183,7 @@ You can now check what blocks have been created by:
hashFunStr, _ := req.Options[hashOptionName].(string)
inline, _ := req.Options[inlineOptionName].(bool)
inlineLimit, _ := req.Options[inlineLimitOptionName].(int)
wrapPathName, _ := req.Options[wrapPathName].(string)

// The arguments are subject to the following constraints.
//
Expand Down Expand Up @@ -287,6 +290,7 @@ You can now check what blocks have been created by:
fileAdder.Silent = silent
fileAdder.RawLeaves = rawblks
fileAdder.NoCopy = nocopy
fileAdder.WpName = wrapPathName
fileAdder.CidBuilder = prefix

if inline {
Expand Down
5 changes: 5 additions & 0 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
bstore "gx/ipfs/QmcmpX42gtDv1fz24kau4wjS9hfwWj5VexWBKgGnWzsyag/go-ipfs-blockstore"
mfs "gx/ipfs/QmdghKsSDa2AD1kC4qYRnVYWqZecdSBRZjeXRdhMYYhafj/go-mfs"
"strings"
)

var log = logging.Logger("coreunix")
Expand Down Expand Up @@ -83,6 +84,7 @@ type Adder struct {
RawLeaves bool
Silent bool
Wrap bool
WpName string
NoCopy bool
Chunker string
root ipld.Node
Expand Down Expand Up @@ -470,6 +472,9 @@ func (adder *Adder) addFile(file files.File) error {
return err
}

if !strings.EqualFold(adder.WpName, "") && adder.Wrap {
return adder.addNode(dagnode, adder.WpName)
}
// patch it into the root
return adder.addNode(dagnode, file.FileName())
}
Expand Down

0 comments on commit 514891d

Please sign in to comment.