From 9df4277263bbeae438dbccb3dbc00e3650e01316 Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Sat, 14 Sep 2024 17:17:33 +0800 Subject: [PATCH] fix: check close error in `oci/storage.go` during ingestion (#830) Fixes #829 --------- Signed-off-by: Lixia (Sylvia) Lei --- content/oci/storage.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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)