Log: Use os.Open to open file for reading (#29483)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2020-12-01 09:28:18 +01:00 committed by GitHub
parent 097dcc456a
commit 3c229c6bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -123,13 +123,13 @@ func (w *FileLogWriter) createLogFile() (*os.File, error) {
}
func (w *FileLogWriter) lineCounter() (int, error) {
r, err := os.OpenFile(w.Filename, os.O_RDONLY, 0644)
r, err := os.Open(w.Filename)
if err != nil {
return 0, fmt.Errorf("lineCounter Open File : %s", err)
return 0, fmt.Errorf("failed to open file %q: %w", w.Filename, err)
}
buf := make([]byte, 32*1024)
count := 0
for {
c, err := r.Read(buf)
count += bytes.Count(buf[:c], []byte{'\n'})