Skip to content

Commit

Permalink
fix: check close error in oci/storage.go during ingestion (#830)
Browse files Browse the repository at this point in the history
Fixes #829

---------

Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia authored Sep 14, 2024
1 parent d6c837e commit 9df4277
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions content/oci/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9df4277

Please sign in to comment.