@cryptotaxi247 / kubo / commits / f66ca2ff2

gc: continue to use cmds.ChannelMarshaler

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Mar 18, 2017 at 21:30 UTC f66ca2ff2442fccfa8a92a3a7912f422fbb93c07
2 files changed +12 -9
commands/channelmarshaler.go
+3
@@ -25,6 +25,9 @@ func (cr *ChannelMarshaler) Read(p []byte) (int, error) {
25 if err != nil {
26 return 0, err
27 }
28 + if r == nil {
29 + return 0, nil
30 + }
31 cr.reader = r
32 }
33
core/commands/repo.go
+9 -9
@@ -110,7 +110,7 @@ order to reclaim hard disk space.
110 return nil, err
111 }
112
113 - for v := range outChan {
113 + marshal := func(v interface{}) (io.Reader, error) {
114 obj, ok := v.(*GcResult)
115 if !ok {
116 return nil, u.ErrCast()
@@ -118,21 +118,21 @@ order to reclaim hard disk space.
118
119 if obj.Error != "" {
120 fmt.Fprintf(res.Stderr(), "Error: %s\n", obj.Error)
121 - continue
121 + return nil, nil
122 }
123
124 if quiet {
125 - fmt.Fprintf(res.Stdout(), "%s\n", obj.Key.String())
125 + return bytes.NewBufferString(obj.Key.String() + "\n"), nil
126 } else {
127 - fmt.Fprintf(res.Stdout(), "removed %s\n", obj.Key.String())
127 + return bytes.NewBufferString(fmt.Sprintf("removed %s\n", obj.Key)), nil
128 }
129 }
130
131 - if res.Error() != nil {
132 - return nil, res.Error()
133 - }
134 -
135 - return nil, nil
131 + return &cmds.ChannelMarshaler{
132 + Channel: outChan,
133 + Marshaler: marshal,
134 + Res: res,
135 + }, nil
136 },
137 },
138 }