From 6898c4a8c2f0b49d473a32ca080b8ea108cbbb51 Mon Sep 17 00:00:00 2001 From: Kejie Zhang <601172892@qq.com> Date: Thu, 23 Aug 2018 19:17:35 +0800 Subject: [PATCH] add --name new flag when ipfs adding from stdin License: MIT Signed-off-by: Kejie Zhang <601172892@qq.com> --- core/commands/add.go | 4 ++++ core/coreunix/add.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/core/commands/add.go b/core/commands/add.go index e3db80864196..c2266c1e0bb3 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -36,6 +36,7 @@ const ( progressOptionName = "progress" trickleOptionName = "trickle" wrapOptionName = "wrap-with-directory" + wrapPathName = "name" hiddenOptionName = "hidden" onlyHashOptionName = "only-hash" chunkerOptionName = "chunker" @@ -113,6 +114,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), @@ -174,6 +176,7 @@ You can now check what blocks have been created by: fscache, _ := req.Options[fstoreCacheOptionName].(bool) cidVer, cidVerSet := req.Options[cidVersionOptionName].(int) hashFunStr, _ := req.Options[hashOptionName].(string) + wrapPathName,_ := req.Options[wrapPathName].(string) // The arguments are subject to the following constraints. // @@ -281,6 +284,7 @@ You can now check what blocks have been created by: fileAdder.RawLeaves = rawblks fileAdder.NoCopy = nocopy fileAdder.CidBuilder = &prefix + fileAdder.WpName = wrapPathName if hash { md := dagtest.Mock() diff --git a/core/coreunix/add.go b/core/coreunix/add.go index ced043b9e1f6..4e93c7d71ec0 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -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") @@ -83,6 +84,7 @@ type Adder struct { RawLeaves bool Silent bool Wrap bool + WpName string NoCopy bool Chunker string root ipld.Node @@ -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()) }