diff --git a/src/line_buffer.cc b/src/line_buffer.cc index 54f7c055..fa236a93 100644 --- a/src/line_buffer.cc +++ b/src/line_buffer.cc @@ -404,7 +404,9 @@ line_buffer::set_fd(auto_fd& fd) void line_buffer::resize_buffer(size_t new_max) { - if (new_max > (size_t) this->lb_buffer.capacity()) { + if (new_max <= MAX_LINE_BUFFER_SIZE + && new_max > (size_t) this->lb_buffer.capacity()) + { /* Still need more space, try a realloc. */ this->lb_share_manager.invalidate_refs(); this->lb_buffer.expand_to(new_max); @@ -1067,7 +1069,7 @@ line_buffer::load_next_line(file_range prev_line) #endif if (lf != nullptr || (retval.li_file_range.fr_size >= MAX_LINE_BUFFER_SIZE) - || (request_size == MAX_LINE_BUFFER_SIZE) + || (request_size >= MAX_LINE_BUFFER_SIZE) || (!got_new_data && (!this->is_pipe() || request_size > DEFAULT_INCREMENT))) { @@ -1122,7 +1124,9 @@ line_buffer::load_next_line(file_range prev_line) if (!this->is_pipe() || !this->is_pipe_closed()) { retval.li_partial = true; } - request_size += DEFAULT_INCREMENT; + request_size + = std::min(this->lb_buffer.size() + DEFAULT_INCREMENT, + MAX_LINE_BUFFER_SIZE); } if (!done diff --git a/src/logfile.cc b/src/logfile.cc index 7281a10b..751395fd 100644 --- a/src/logfile.cc +++ b/src/logfile.cc @@ -479,6 +479,7 @@ logfile::rebuild_index(nonstd::optional deadline) this->lf_line_buffer.flush_at(0); } } else { + this->lf_line_buffer.flush_at(0); off = 0; } if (this->lf_logline_observer != nullptr) { diff --git a/src/piper_proc.cc b/src/piper_proc.cc index aeb1ac56..396f175c 100644 --- a/src/piper_proc.cc +++ b/src/piper_proc.cc @@ -172,7 +172,8 @@ piper_proc::piper_proc(auto_fd pipefd, bool timestamp, auto_fd filefd) woff += wrc; last_range = li.li_file_range; - if (sbr.get_data()[sbr.length() - 1] != '\n' + if (li.li_partial + && sbr.get_data()[sbr.length() - 1] != '\n' && (last_range.next_offset() != lb.get_file_size())) { woff = last_woff; diff --git a/test/Makefile.am b/test/Makefile.am index fd09a656..833880fb 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -467,6 +467,7 @@ DISTCLEANFILES = \ logfile_syslog_test.2 \ logfile_syslog_fr_test.0 \ logfile_syslog_with_mixed_times_test.0 \ + textfile_long_lines.0 \ not:a:remote:file \ rollover_in.0 \ test-logs.tgz \ diff --git a/test/expected/expected.am b/test/expected/expected.am index 1a1a40b9..1e3cdfc8 100644 --- a/test/expected/expected.am +++ b/test/expected/expected.am @@ -8,6 +8,8 @@ EXPECTED_FILES = \ $(srcdir)/%reldir%/test_cli.sh_97e19b9ff3775d84074455a2e8993a0611b1c269.out \ $(srcdir)/%reldir%/test_cli.sh_a1a09f890f4604309d0a81bbbec8e50fb7d5e887.err \ $(srcdir)/%reldir%/test_cli.sh_a1a09f890f4604309d0a81bbbec8e50fb7d5e887.out \ + $(srcdir)/%reldir%/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.err \ + $(srcdir)/%reldir%/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.out \ $(srcdir)/%reldir%/test_cmds.sh_017b495b95218b7c083951e2dba331cfec6e90be.err \ $(srcdir)/%reldir%/test_cmds.sh_017b495b95218b7c083951e2dba331cfec6e90be.out \ $(srcdir)/%reldir%/test_cmds.sh_0b1e4b1523dfca71927b1fe721c74490c51361d1.err \ diff --git a/test/expected/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.err b/test/expected/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.err new file mode 100644 index 00000000..e69de29b diff --git a/test/expected/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.out b/test/expected/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.out new file mode 100644 index 00000000..751c83b4 --- /dev/null +++ b/test/expected/test_cli.sh_f2e41555f1a5f40f54ce241207af602ed1503a2b.out @@ -0,0 +1,2 @@ +filepath lines  +stdin   4  diff --git a/test/test_cli.sh b/test/test_cli.sh index 6bca26b9..be773f5e 100644 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -17,3 +17,15 @@ run_cap_test ${lnav_test} -nr nested printf "a\ba _\ba a\b_" | run_cap_test env TEST_COMMENT="overstrike bold" \ ${lnav_test} -n + +{ + echo "This is the start of a file with long lines" + ${lnav_test} -nN \ + -c ";select replicate('abcd', 2 * 1024 * 1024)" -c ':write-raw-to -' + echo "abcd" + echo "Goodbye" +} > textfile_long_lines.0 + +grep abcd textfile_long_lines.0 | run_cap_test \ + ${lnav_test} -n -d /tmp/lnav.err \ + -c ';SELECT filepath, lines FROM lnav_file'