[line_buffer] fix some long-line handling

This commit is contained in:
Tim Stack 2022-09-04 06:38:39 -07:00
parent 7309352c97
commit 6ca01cd934
8 changed files with 27 additions and 4 deletions

View File

@ -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<ssize_t>(this->lb_buffer.size() + DEFAULT_INCREMENT,
MAX_LINE_BUFFER_SIZE);
}
if (!done

View File

@ -479,6 +479,7 @@ logfile::rebuild_index(nonstd::optional<ui_clock::time_point> deadline)
this->lf_line_buffer.flush_at(0);
}
} else {
this->lf_line_buffer.flush_at(0);
off = 0;
}
if (this->lf_logline_observer != nullptr) {

View File

@ -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;

View File

@ -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 \

View File

@ -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 \

View File

@ -0,0 +1,2 @@
filepath lines 
stdin   4 

View File

@ -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'