Skip to content

Commit

Permalink
drop wrap check and modify parameter name
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 Sep 3, 2018
1 parent 514891d commit 02b6092
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
progressOptionName = "progress"
trickleOptionName = "trickle"
wrapOptionName = "wrap-with-directory"
wrapPathName = "name"
pathName = "name"
hiddenOptionName = "hidden"
onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker"
Expand Down Expand Up @@ -117,7 +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.StringOption(pathName, "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 @@ -183,7 +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)
pathName, _ := req.Options[pathName].(string)

// The arguments are subject to the following constraints.
//
Expand Down Expand Up @@ -290,7 +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.Name = pathName
fileAdder.CidBuilder = prefix

if inline {
Expand Down
27 changes: 14 additions & 13 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ import (
"path/filepath"
"strconv"

core "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/pin"
unixfs "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs"
balanced "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/balanced"
"gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs"
"gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/balanced"
ihelper "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/helpers"
trickle "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/trickle"
"gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/trickle"
dag "gx/ipfs/QmRiQCJZ91B7VNmLvA6sxzDuBJGSojS3uXHHVuNr3iueNZ/go-merkledag"

logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log"
files "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit/files"
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit/files"
ipld "gx/ipfs/QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC/go-ipld-format"
posinfo "gx/ipfs/QmXD4grfThQ4LwVoEEfe4dgR7ukmbV9TppM5Q4SPowp7hU/go-ipfs-posinfo"
"gx/ipfs/QmXD4grfThQ4LwVoEEfe4dgR7ukmbV9TppM5Q4SPowp7hU/go-ipfs-posinfo"
chunker "gx/ipfs/QmXzBbJo2sLf3uwjNTeoWYiJV7CjAhkiA4twtLvwJSSNdK/go-ipfs-chunker"
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
"gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
bstore "gx/ipfs/QmcmpX42gtDv1fz24kau4wjS9hfwWj5VexWBKgGnWzsyag/go-ipfs-blockstore"
mfs "gx/ipfs/QmdghKsSDa2AD1kC4qYRnVYWqZecdSBRZjeXRdhMYYhafj/go-mfs"
"strings"
"gx/ipfs/QmdghKsSDa2AD1kC4qYRnVYWqZecdSBRZjeXRdhMYYhafj/go-mfs"
)

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

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

func (adder *Adder) addDir(dir files.File) error {
Expand Down

0 comments on commit 02b6092

Please sign in to comment.