Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #2657 from ipfs/feature/add-defaults-to-add" #3239

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ const (

var AddCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Add a file to ipfs.",
Tagline: "Add a file or directory to ipfs.",
ShortDescription: `
Adds contents of <path> to ipfs. Use -r to add directories.
Note that directories are added recursively, to form the ipfs
MerkleDAG.
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
`,
LongDescription: `
Adds contents of <path> to ipfs. Use -r to add directories.
Expand Down Expand Up @@ -69,26 +67,29 @@ You can now refer to the added file in a gateway, like so:
},
Options: []cmds.Option{
cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false),
cmds.BoolOption(silentOptionName, "Write no output.").Default(false),
cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
cmds.BoolOption(silentOptionName, "Write no output."),
cmds.BoolOption(progressOptionName, "p", "Stream progress data."),
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false),
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false),
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false),
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").Default(false),
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true),
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default: true."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be ".Default(true)."

},
PreRun: func(req cmds.Request) error {
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
return nil
}

_, found, _ := req.Option(progressOptionName).Bool()
// ipfs cli progress bar defaults to true
progress, found, _ := req.Option(progressOptionName).Bool()
if !found {
req.SetOption(progressOptionName, true)
progress = true
}

req.SetOption(progressOptionName, progress)

sizeFile, ok := req.Files().(files.SizeFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I don't understand what is going on here. Why are we setting progressOptionName if it is not found. See my note in the PostRun function.

if !ok {
// we don't need to error, the progress bar just won't know how big the files are
Expand Down Expand Up @@ -134,7 +135,11 @@ You can now refer to the added file in a gateway, like so:
hidden, _, _ := req.Option(hiddenOptionName).Bool()
silent, _, _ := req.Option(silentOptionName).Bool()
chunker, _, _ := req.Option(chunkerOptionName).String()
dopin, _, _ := req.Option(pinOptionName).Bool()
dopin, pin_found, _ := req.Option(pinOptionName).Bool()

if !pin_found { // default
dopin = true
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if !pin_found {...} should not be necessary. See earlier comment.

if hash {
nilnode, err := core.NewNode(n.Context(), &core.BuildCfg{
Expand Down Expand Up @@ -242,7 +247,7 @@ You can now refer to the added file in a gateway, like so:
return
}

progress, _, err := req.Option(progressOptionName).Bool()
progress, prgFound, err := req.Option(progressOptionName).Bool()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Okay so how is it that prgFound can be false, it we explicitly set it the PreRun. I am very unsure of the correct behavior here. What was the original intention. @whyrusleeping @Kubuxu any ideas?

res.SetError(u.ErrCast(), cmds.ErrNormal)
return
Expand All @@ -254,12 +259,17 @@ You can now refer to the added file in a gateway, like so:
return
}

if !quiet && !silent {
progress = true
var showProgressBar bool
if prgFound {
showProgressBar = progress
} else if !quiet && !silent {
showProgressBar = true
}

var bar *pb.ProgressBar
if progress {

var terminalWidth int
if showProgressBar {
bar = pb.New64(0).SetUnits(pb.U_BYTES)
bar.ManualUpdate = true
bar.ShowTimeLeft = false
Expand All @@ -286,7 +296,7 @@ You can now refer to the added file in a gateway, like so:
}
output := out.(*coreunix.AddedObject)
if len(output.Hash) > 0 {
if progress {
if showProgressBar {
// clear progress bar line before we print "added x" output
fmt.Fprintf(res.Stderr(), "\033[2K\r")
}
Expand All @@ -299,7 +309,7 @@ You can now refer to the added file in a gateway, like so:
} else {
log.Debugf("add progress: %v %v\n", output.Name, output.Bytes)

if !progress {
if !showProgressBar {
continue
}

Expand All @@ -315,11 +325,11 @@ You can now refer to the added file in a gateway, like so:
totalProgress = bar.Add64(delta)
}

if progress {
if showProgressBar {
bar.Update()
}
case size := <-sizeChan:
if progress {
if showProgressBar {
bar.Total = size
bar.ShowPercent = true
bar.ShowBar = true
Expand Down