Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
[bug] - Fix disk write metric and update BufferedFileWriter file field (#2733)
ahravf03aa387266d
diff --git a/pkg/writers/buffered_file_writer/bufferedfilewriter.go b/pkg/writers/buffered_file_writer/bufferedfilewriter.goindex 85dcfbc53..6d254d581 100644--- a/pkg/writers/buffered_file_writer/bufferedfilewriter.go+++ b/pkg/writers/buffered_file_writer/bufferedfilewriter.go@@ -55,7 +55,7 @@ type BufferedFileWriter struct {bufPool *buffer.Pool // Pool for storing buffers for reuse.buf *buffer.Buffer // Buffer for storing data under the threshold in memory.filename string // Name of the temporary file.- file io.WriteCloser // File for storing data over the threshold.+ file *os.File // File for storing data over the threshold.state state // Current state of the writer. (writeOnly or readOnly)@@ -149,7 +149,6 @@ func (w *BufferedFileWriter) Write(data []byte) (int, error) {w.filename = file.Name()w.file = file- w.metrics.recordDiskWrite(file)// Transfer existing data in buffer to the file, then clear the buffer.// This ensures all the data is in one place - either entirely in the buffer or the file.@@ -161,7 +160,14 @@ func (w *BufferedFileWriter) Write(data []byte) (int, error) {}}- return w.file.Write(data)+ n, err := w.file.Write(data)+ if err != nil {+ return n, err+ }++ w.metrics.recordDiskWrite(w.file)++ return n, nil}// CloseForWriting flushes any remaining data in the buffer to the file, closes the file if created,