Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39db30c

Browse files
committedJan 12, 2016
add context to files reading
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent afcf8ca commit 39db30c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎core/commands/files/files.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Examples:
361361
res.SetError(err, cmds.ErrNormal)
362362
return
363363
}
364-
var r io.Reader = fi
364+
var r io.Reader = &contextReaderWrapper{R: fi, ctx: req.Context()}
365365
count, found, err := req.Option("count").Int()
366366
if err != nil {
367367
res.SetError(err, cmds.ErrNormal)
@@ -379,6 +379,19 @@ Examples:
379379
},
380380
}
381381

382+
type contextReader interface {
383+
CtxReadFull(context.Context, []byte) (int, error)
384+
}
385+
386+
type contextReaderWrapper struct {
387+
R contextReader
388+
ctx context.Context
389+
}
390+
391+
func (crw *contextReaderWrapper) Read(b []byte) (int, error) {
392+
return crw.R.CtxReadFull(crw.ctx, b)
393+
}
394+
382395
var FilesMvCmd = &cmds.Command{
383396
Helptext: cmds.HelpText{
384397
Tagline: "Move files",

0 commit comments

Comments
 (0)
Please sign in to comment.