Skip to content

Commit

Permalink
Handle a failure when closing compressor.
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Nov 28, 2024
1 parent 570d133 commit 1ccd7f8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ccd7f8

Please sign in to comment.