Skip to content

Commit

Permalink
check close error in oci storage
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia committed Sep 14, 2024
1 parent d6c837e commit e7333df
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions content/oci/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,18 @@ func (s *Storage) ingest(expected ocispec.Descriptor, content io.Reader) (path s
if err != nil {
return "", fmt.Errorf("failed to create ingest file: %w", err)
}

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)

Check warning on line 145 in content/oci/storage.go

View check run for this annotation

Codecov / codecov/patch

content/oci/storage.go#L145

Added line #L145 was not covered by tests
}

// 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 All @@ -160,7 +162,7 @@ func (s *Storage) ingest(expected ocispec.Descriptor, content io.Reader) (path s
return "", fmt.Errorf("failed to make readonly: %w", err)
}

return
return path, nil
}

// ensureDir ensures the directories of the path exists.
Expand Down

0 comments on commit e7333df

Please sign in to comment.