-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(store): extract (*Store).saveChunk method #15144
Conversation
There was a valid, but ignored, linter warning about a deferred close in a loop. Extract a method so that the defer can exist in a more narrow function scope, instead of each defer accumulating as the channel is iterated. While here, only call os.MkdirAll once at the start, instead of repeatedly with the same arguments on every chunk encountered. Also distinguish the wrapped error message when closing the chunk file vs. the incoming chunk body.
defer chunkBody.Close() | ||
|
||
path := s.pathChunk(snapshot.Height, snapshot.Format, index) | ||
chunkFile, err := os.Create(path) |
Check failure
Code scanning / gosec
Potential file inclusion via variable
// the whole operation will fail anyway. | ||
if !dirCreated { | ||
dir := s.pathSnapshot(height, format) | ||
if err := os.MkdirAll(dir, 0o755); err != nil { |
Check failure
Code scanning / gosec
Expect directory permissions to be 0750 or less
// The hash of the chunk is appended to the snapshot's metadata, | ||
// and the overall snapshot hash is updated with the chunk content too. | ||
func (s *Store) saveChunk(chunkBody io.ReadCloser, index uint32, snapshot *types.Snapshot, chunkHasher, snapshotHasher hash.Hash) error { | ||
defer chunkBody.Close() |
Check failure
Code scanning / gosec
Deferring unsafe method "Close" on type "io.WriteCloser"
if err != nil { | ||
return errors.Wrapf(err, "failed to create snapshot chunk file %q", path) | ||
} | ||
defer chunkFile.Close() |
Check failure
Code scanning / gosec
Deferring unsafe method "Close" on type "io.WriteCloser"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
Description
There was a valid, but ignored, linter warning about a deferred close in a loop. Extract a method so that the defer can exist in a more narrow function scope, instead of each defer accumulating as the channel is iterated.
While here, only call os.MkdirAll once at the start, instead of repeatedly with the same arguments on every chunk encountered. Also distinguish the wrapped error message when closing the chunk file vs. the incoming chunk body.
Author Checklist
I have...
!
to the type prefix if API or client breaking changeprovided a link to the relevant issue or specificationfollowed the guidelines for building modulesincluded the necessary unit and integration testsCHANGELOG.md
updated the relevant documentation or specificationReviewers Checklist
I have...
!
in the type prefix if API or client breaking change