mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
client: Client.ContainerExport: close reader on context cancellation
Use a cancelReadCloser to automatically close the reader when the context is cancelled. Consumers are still recommended to manually close the reader, but the cancelReadCloser makes the Close idempotent. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -103,11 +103,11 @@ func (s *DockerAPISuite) TestContainerAPIGetExport(c *testing.T) {
|
||||
assert.NilError(c, err)
|
||||
defer apiClient.Close()
|
||||
|
||||
body, err := apiClient.ContainerExport(testutil.GetContext(c), name, client.ContainerExportOptions{})
|
||||
res, err := apiClient.ContainerExport(testutil.GetContext(c), name, client.ContainerExportOptions{})
|
||||
assert.NilError(c, err)
|
||||
defer body.Close()
|
||||
defer res.Close()
|
||||
found := false
|
||||
for tarReader := tar.NewReader(body); ; {
|
||||
for tarReader := tar.NewReader(res); ; {
|
||||
h, err := tarReader.Next()
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user