From 1ccd7f899d0e5273369d6d27ac8190ea4663bfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 28 Nov 2024 20:05:59 +0100 Subject: [PATCH] Handle a failure when closing compressor. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač --- storage/storage_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/storage_test.go b/storage/storage_test.go index 6f90495fd..fc7e63e99 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -189,14 +189,18 @@ func TestParseWithGraphDriverOptions(t *testing.T) { // makeLayerGoroutine writes to pwriter, and on success, updates uncompressedCount // before it terminates. -func makeLayerGoroutine(pwriter io.Writer, uncompressedCount *int64, compression archive.Compression) error { +func makeLayerGoroutine(pwriter io.Writer, uncompressedCount *int64, compression archive.Compression) (retErr error) { var uncompressed *ioutils.WriteCounter if compression != archive.Uncompressed { compressor, err := archive.CompressStream(pwriter, compression) if err != nil { return fmt.Errorf("compressing layer: %w", err) } - defer compressor.Close() + defer func() { + if err := compressor.Close(); err != nil && retErr == nil { + retErr = err + } + }() uncompressed = ioutils.NewWriteCounter(compressor) } else { uncompressed = ioutils.NewWriteCounter(pwriter)