mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: ImageImportResult: prevent panic on nil reader
This panicked when creating a stub; we need to look for better ways to allow stubbing these (perhaps we need to expose the rc / body)? Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -20,16 +20,19 @@ type ImageImportOptions struct {
|
||||
|
||||
// ImageImportResult holds the response body returned by the daemon for image import.
|
||||
type ImageImportResult struct {
|
||||
body io.ReadCloser
|
||||
rc io.ReadCloser
|
||||
}
|
||||
|
||||
func (r ImageImportResult) Read(p []byte) (n int, err error) {
|
||||
return r.body.Read(p)
|
||||
if r.rc == nil {
|
||||
return 0, io.EOF
|
||||
}
|
||||
return r.rc.Read(p)
|
||||
}
|
||||
|
||||
func (r ImageImportResult) Close() error {
|
||||
if r.body == nil {
|
||||
if r.rc == nil {
|
||||
return nil
|
||||
}
|
||||
return r.body.Close()
|
||||
return r.rc.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user