Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check close error in oci/storage.go during ingestion #830

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
return "", fmt.Errorf("failed to make readonly: %w", err)
}

return
return path, nil
}

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