From 378116a84f2dbcf054a021ecb67d1528f77ba2eb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 24 Oct 2025 13:22:49 +0200 Subject: [PATCH] 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 --- client/image_import.go | 2 +- client/image_import_opts.go | 11 +++++++---- vendor/github.com/moby/moby/client/image_import.go | 2 +- .../github.com/moby/moby/client/image_import_opts.go | 11 +++++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/image_import.go b/client/image_import.go index ca0fa1d0f6..b8f1ccb500 100644 --- a/client/image_import.go +++ b/client/image_import.go @@ -42,5 +42,5 @@ func (cli *Client) ImageImport(ctx context.Context, source ImageImportSource, re if err != nil { return ImageImportResult{}, err } - return ImageImportResult{body: resp.Body}, nil + return ImageImportResult{rc: resp.Body}, nil } diff --git a/client/image_import_opts.go b/client/image_import_opts.go index 44ea0e2caa..2ba5b593ec 100644 --- a/client/image_import_opts.go +++ b/client/image_import_opts.go @@ -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() } diff --git a/vendor/github.com/moby/moby/client/image_import.go b/vendor/github.com/moby/moby/client/image_import.go index ca0fa1d0f6..b8f1ccb500 100644 --- a/vendor/github.com/moby/moby/client/image_import.go +++ b/vendor/github.com/moby/moby/client/image_import.go @@ -42,5 +42,5 @@ func (cli *Client) ImageImport(ctx context.Context, source ImageImportSource, re if err != nil { return ImageImportResult{}, err } - return ImageImportResult{body: resp.Body}, nil + return ImageImportResult{rc: resp.Body}, nil } diff --git a/vendor/github.com/moby/moby/client/image_import_opts.go b/vendor/github.com/moby/moby/client/image_import_opts.go index 44ea0e2caa..2ba5b593ec 100644 --- a/vendor/github.com/moby/moby/client/image_import_opts.go +++ b/vendor/github.com/moby/moby/client/image_import_opts.go @@ -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() }