From f66ca2ff2442fccfa8a92a3a7912f422fbb93c07 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Sat, 18 Mar 2017 21:30:32 -0400 Subject: [PATCH] gc: continue to use cmds.ChannelMarshaler License: MIT Signed-off-by: Kevin Atkinson --- commands/channelmarshaler.go | 3 +++ core/commands/repo.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/commands/channelmarshaler.go b/commands/channelmarshaler.go index 02cc4545e03..0c731ee8cd4 100644 --- a/commands/channelmarshaler.go +++ b/commands/channelmarshaler.go @@ -25,6 +25,9 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) { if err != nil { return 0, err } + if r == nil { + return 0, nil + } cr.reader = r } diff --git a/core/commands/repo.go b/core/commands/repo.go index 6e929f6e0ee..b34010e667a 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -110,7 +110,7 @@ order to reclaim hard disk space. return nil, err } - for v := range outChan { + marshal := func(v interface{}) (io.Reader, error) { obj, ok := v.(*GcResult) if !ok { return nil, u.ErrCast() @@ -118,21 +118,21 @@ order to reclaim hard disk space. if obj.Error != "" { fmt.Fprintf(res.Stderr(), "Error: %s\n", obj.Error) - continue + return nil, nil } if quiet { - fmt.Fprintf(res.Stdout(), "%s\n", obj.Key.String()) + return bytes.NewBufferString(obj.Key.String() + "\n"), nil } else { - fmt.Fprintf(res.Stdout(), "removed %s\n", obj.Key.String()) + return bytes.NewBufferString(fmt.Sprintf("removed %s\n", obj.Key)), nil } } - if res.Error() != nil { - return nil, res.Error() - } - - return nil, nil + return &cmds.ChannelMarshaler{ + Channel: outChan, + Marshaler: marshal, + Res: res, + }, nil }, }, }