Skip to content
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

Fix tail n=0 case #725

Merged
merged 1 commit into from
May 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions object/datastore_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ func lastIndexLines(s []byte, line *int, include func(l int, m string) bool) (in

// Tail seeks to the position of the last N lines of the file.
func (f *DatastoreFile) Tail(n int) error {
return f.TailFunc(func(line int, _ string) bool { return n > line })
return f.TailFunc(n, func(line int, _ string) bool { return n > line })
}

// TailFunc will seek backwards in the datastore file until it hits a line that does
// not satisfy the supplied `include` function.
func (f *DatastoreFile) TailFunc(include func(line int, message string) bool) error {
func (f *DatastoreFile) TailFunc(lines int, include func(line int, message string) bool) error {
// Read the file in reverse using bsize chunks
const bsize = int64(1024 * 16)

Expand All @@ -270,6 +270,10 @@ func (f *DatastoreFile) TailFunc(include func(line int, message string) bool) er
return err
}

if lines == 0 {
return nil
}

chunk := int64(-1)

buf := bytes.NewBuffer(make([]byte, 0, bsize))
Expand Down