From 9b679afe393b3208b15a73d447b37f7284d5c47a Mon Sep 17 00:00:00 2001 From: William Flores Date: Sun, 12 Apr 2020 23:59:28 -0700 Subject: [PATCH 1/3] feat(cmd): add silent option repo gc command closes #7129 --- core/commands/repo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/commands/repo.go b/core/commands/repo.go index 20cc41fcd91..cec843e3e08 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -51,6 +51,7 @@ type GcResult struct { const ( repoStreamErrorsOptionName = "stream-errors" repoQuietOptionName = "quiet" + repoSilentOptionName = "silent" ) var repoGcCmd = &cmds.Command{ @@ -65,6 +66,7 @@ order to reclaim hard disk space. Options: []cmds.Option{ cmds.BoolOption(repoStreamErrorsOptionName, "Stream errors."), cmds.BoolOption(repoQuietOptionName, "q", "Write minimal output."), + cmds.BoolOption(repoSilentOptionName, "Write no output."), }, Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { n, err := cmdenv.GetNode(env) @@ -111,6 +113,11 @@ order to reclaim hard disk space. Encoders: cmds.EncoderMap{ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, gcr *GcResult) error { quiet, _ := req.Options[repoQuietOptionName].(bool) + silent, _ := req.Options[repoSilentOptionName].(bool) + + if silent { + return nil + } if gcr.Error != "" { _, err := fmt.Fprintf(w, "Error: %s\n", gcr.Error) From 43459c98b729e4cdbb9afd26ff5f5e8435e1f4c5 Mon Sep 17 00:00:00 2001 From: William Flores Date: Mon, 13 Apr 2020 11:36:07 -0700 Subject: [PATCH 2/3] test(cmd): add test case for silent option for command repo gc --- test/sharness/t0080-repo.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/sharness/t0080-repo.sh b/test/sharness/t0080-repo.sh index a6631b53cfc..839e651d1c5 100755 --- a/test/sharness/t0080-repo.sh +++ b/test/sharness/t0080-repo.sh @@ -55,6 +55,17 @@ test_expect_success "ipfs repo gc fully reverse ipfs add (part 1)" ' ipfs pin rm -r $hash && ipfs repo gc ' +test_expect_success "'ipfs repo gc --silent' succeeds (no output)" ' + echo "should be empty" >bfile && + HASH2=`ipfs add -q bfile` && + ipfs cat "$HASH2" >expected11 && + test_cmp expected11 bfile && + ipfs pin rm -r "$HASH2" && + ipfs repo gc --silent >gc_out_empty && + test_cmp /dev/null gc_out_empty && + test_must_fail ipfs cat "$HASH2" 2>err_expected1 && + grep "Error: merkledag: not found" err_expected1 +' test_kill_ipfs_daemon From 85e8bfb7288f3cc7ce936428e90b6eb321d873f1 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 18 Feb 2022 21:56:31 +0100 Subject: [PATCH 3/3] fix: no emit on server with --silent This removes unnecessary send to the client that does not care --- core/commands/repo.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/commands/repo.go b/core/commands/repo.go index cec843e3e08..c4066f50e56 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -74,6 +74,7 @@ order to reclaim hard disk space. return err } + silent, _ := req.Options[repoSilentOptionName].(bool) streamErrors, _ := req.Options[repoStreamErrorsOptionName].(bool) gcOutChan := corerepo.GarbageCollectAsync(n, req.Context) @@ -97,6 +98,9 @@ order to reclaim hard disk space. } } else { err := corerepo.CollectResult(req.Context, gcOutChan, func(k cid.Cid) { + if silent { + return + } // Nothing to do with this error, really. This // most likely means that the client is gone but // we still need to let the GC finish.