From a9417a144c7aea9de12366bf78567bef6325075d Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Sun, 4 Mar 2018 01:24:54 +0100 Subject: [PATCH] fix `ipfs pin verify --verbose` not working Resolves https://github.com/ipfs/go-ipfs/issues/4761 License: MIT Signed-off-by: Jakub Sztandera --- core/commands/pin.go | 28 +++++++++++++--------------- test/sharness/t0085-pins.sh | 9 +++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/core/commands/pin.go b/core/commands/pin.go index ddb470064..a68b75424 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -462,25 +462,23 @@ var verifyPinCmd = &cmds.Command{ cmds.Text: func(res cmds.Response) (io.Reader, error) { quiet, _, _ := res.Request().Option("quiet").Bool() - outChan, ok := res.Output().(<-chan interface{}) + out, err := unwrapOutput(res.Output()) + if err != nil { + return nil, err + } + r, ok := out.(*PinVerifyRes) if !ok { - return nil, u.ErrCast() + return nil, e.TypeErr(r, out) } - rdr, wtr := io.Pipe() - go func() { - defer wtr.Close() - for r0 := range outChan { - r := r0.(*PinVerifyRes) - if quiet && !r.Ok { - fmt.Fprintf(wtr, "%s\n", r.Cid) - } else if !quiet { - r.Format(wtr) - } - } - }() + buf := &bytes.Buffer{} + if quiet && !r.Ok { + fmt.Fprintf(buf, "%s\n", r.Cid) + } else if !quiet { + r.Format(buf) + } - return rdr, nil + return buf, nil }, }, } diff --git a/test/sharness/t0085-pins.sh b/test/sharness/t0085-pins.sh index 4f17f00c9..5f2db3548 100755 --- a/test/sharness/t0085-pins.sh +++ b/test/sharness/t0085-pins.sh @@ -36,6 +36,15 @@ test_pins() { cat hashes | ipfs pin add $EXTRA_ARGS ' + test_expect_success "see if verify works" ' + ipfs pin verify + ' + + test_expect_success "see if verify --verbose works" ' + ipfs pin verify --verbose > verify_out && + test $(cat verify_out | wc -l) > 8 + ' + test_expect_success "unpin those hashes" ' cat hashes | ipfs pin rm '