diff --git a/content/oci/storage.go b/content/oci/storage.go index 0a3dec37..f9b0a71b 100644 --- a/content/oci/storage.go +++ b/content/oci/storage.go @@ -141,13 +141,16 @@ func (s *Storage) ingest(expected ocispec.Descriptor, content io.Reader) (path s path = fp.Name() defer func() { - // remove the temp file in case of error. - // this executes after the file is closed. + // close the temp file and check close error + if err := fp.Close(); err != nil && ingestErr == nil { + ingestErr = fmt.Errorf("failed to close ingest file: %w", err) + } + + // remove the temp file in case of error if ingestErr != nil { os.Remove(path) } }() - defer fp.Close() buf := bufPool.Get().(*[]byte) defer bufPool.Put(buf)