Commit 3c229c6b by Arve Knudsen Committed by GitHub

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

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
parent 097dcc45
...@@ -123,13 +123,13 @@ func (w *FileLogWriter) createLogFile() (*os.File, error) { ...@@ -123,13 +123,13 @@ func (w *FileLogWriter) createLogFile() (*os.File, error) {
} }
func (w *FileLogWriter) lineCounter() (int, 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 { 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) buf := make([]byte, 32*1024)
count := 0 count := 0
for { for {
c, err := r.Read(buf) c, err := r.Read(buf)
count += bytes.Count(buf[:c], []byte{'\n'}) count += bytes.Count(buf[:c], []byte{'\n'})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment