Skip to content

Commit ceb07be

Browse files
authored
fix return EOF failure on lines with trailing empty lines (#5176)
1 parent 5ce725b commit ceb07be

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cmd/head-main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"compress/bzip2"
2323
"compress/gzip"
2424
"context"
25+
"errors"
2526
"io"
2627
"os"
2728
"strings"
@@ -142,9 +143,12 @@ func headOut(r io.Reader, nlines int64) *probe.Error {
142143
}
143144

144145
for nlines > 0 {
145-
line, _, e := br.ReadLine()
146-
if e != nil {
147-
return probe.NewError(e)
146+
line, _, err := br.ReadLine()
147+
if err != nil && !errors.Is(err, io.EOF) {
148+
return probe.NewError(err)
149+
}
150+
if errors.Is(err, io.EOF) {
151+
break
148152
}
149153
if _, e := stdout.Write(line); e != nil {
150154
switch e := e.(type) {

0 commit comments

Comments
 (0)