Skip to content

Commit 4f0c945

Browse files
committed
[fs] check for file with hash before splitting
Related to #1553
1 parent 0951f3d commit 4f0c945

8 files changed

Lines changed: 23 additions & 4 deletions

src/base/fs_util.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,8 @@ path_transcoder::to_shell_arg(std::string arg)
315315
std::pair<std::string, file_location_t>
316316
split_file_location(const std::string& file_path_str)
317317
{
318-
auto hash_index = file_path_str.rfind('#');
319-
if (hash_index != std::string::npos) {
320-
return std::make_pair(file_path_str.substr(0, hash_index),
321-
file_path_str.substr(hash_index));
318+
if (access(file_path_str.c_str(), R_OK) == 0) {
319+
return {file_path_str, file_location_t{mapbox::util::no_init{}}};
322320
}
323321

324322
auto colon_index = file_path_str.rfind(':');
@@ -336,6 +334,12 @@ split_file_location(const std::string& file_path_str)
336334
file_path_str.c_str());
337335
}
338336

337+
auto hash_index = file_path_str.rfind('#');
338+
if (hash_index != std::string::npos) {
339+
return std::make_pair(file_path_str.substr(0, hash_index),
340+
file_path_str.substr(hash_index));
341+
}
342+
339343
return std::make_pair(file_path_str,
340344
file_location_t{mapbox::util::no_init{}});
341345
}

src/logfile_sub_source.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,14 @@ logfile_sub_source::rebuild_index(std::optional<ui_clock::time_point> deadline)
10381038
}
10391039
}
10401040

1041+
if (!all_time_ordered_formats
1042+
&& retval == rebuild_result::rr_partial_rebuild)
1043+
{
1044+
force = true;
1045+
full_sort = true;
1046+
retval = rebuild_result::rr_full_rebuild;
1047+
}
1048+
10411049
if (this->lss_index.reserve(total_lines + est_remaining_lines)) {
10421050
// The index array was reallocated, just do a full sort/rebuild since
10431051
// it's been cleared out.

test/#with/bye.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bye

test/#with/hw.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

test/expected/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ dist_noinst_DATA = \
478478
test_logfile.sh_ccb0d31813367c8d9dc5b5df383fac5b780711c1.out \
479479
test_logfile.sh_d14f6d8888652321206549df8a9535399f0fd372.err \
480480
test_logfile.sh_d14f6d8888652321206549df8a9535399f0fd372.out \
481+
test_logfile.sh_d6a1bccd9d5e7cfe2c3a76552d99b66e78d09fc9.err \
482+
test_logfile.sh_d6a1bccd9d5e7cfe2c3a76552d99b66e78d09fc9.out \
481483
test_logfile.sh_de8d59879fe6aa5a012b0748ff77ae26c07aea89.err \
482484
test_logfile.sh_de8d59879fe6aa5a012b0748ff77ae26c07aea89.out \
483485
test_logfile.sh_e333be9b8e7322b0e5e09b1e49e11eca8c468dee.err \

test/expected/test_logfile.sh_d6a1bccd9d5e7cfe2c3a76552d99b66e78d09fc9.err

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bye

test/test_logfile.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,3 +778,5 @@ run_cap_test ${lnav_test} -n ${test_dir}/logfile_logfmt.0
778778
run_cap_test ${lnav_test} -n ${test_dir}/logfile_laravel.0
779779

780780
run_cap_test ${lnav_test} -n ${test_dir}/logfile_laravel.1
781+
782+
run_cap_test ${lnav_test} -n ${test_dir}/\#with

0 commit comments

Comments
 (0)