summaryrefslogtreecommitdiffstats
path: root/src/lnav.indexing.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lnav.indexing.cc110
1 files changed, 83 insertions, 27 deletions
diff --git a/src/lnav.indexing.cc b/src/lnav.indexing.cc
index d2a68d7..345d5df 100644
--- a/src/lnav.indexing.cc
+++ b/src/lnav.indexing.cc
@@ -29,12 +29,15 @@
#include "lnav.indexing.hh"
+#include "bound_tags.hh"
#include "lnav.events.hh"
#include "lnav.hh"
#include "service_tags.hh"
#include "session_data.hh"
+#include "sql_util.hh"
using namespace std::chrono_literals;
+using namespace lnav::roles::literals;
/**
* Observer for loading progress that updates the bottom status bar.
@@ -87,7 +90,7 @@ do_observer_update(const std::shared_ptr<logfile>& lf)
}
lnav_data.ld_status_refresher();
if (lf && lnav_data.ld_mode == ln_mode_t::FILES
- && !lnav_data.ld_initial_build)
+ && lnav_data.ld_exec_phase < lnav_exec_phase::INTERACTIVE)
{
auto& fc = lnav_data.ld_active_files;
auto iter = std::find(fc.fc_files.begin(), fc.fc_files.end(), lf);
@@ -131,6 +134,12 @@ public:
void promote_file(const std::shared_ptr<logfile>& lf) override
{
+ auto& ftf = lnav_data.ld_files_to_front;
+
+ ftf.remove_if([&lf](const auto& elem) {
+ return elem.first == lf->get_filename()
+ || elem.first == lf->get_open_options().loo_filename;
+ });
if (lnav_data.ld_log_source.insert_file(lf)) {
this->did_promotion = true;
log_info("promoting text file to log file: %s (%s)",
@@ -167,8 +176,11 @@ public:
void scanned_file(const std::shared_ptr<logfile>& lf) override
{
- if (!lnav_data.ld_files_to_front.empty()
- && lnav_data.ld_files_to_front.front().first == lf->get_filename())
+ const auto& ftf = lnav_data.ld_files_to_front;
+
+ if (!ftf.empty()
+ && (ftf.front().first == lf->get_filename()
+ || ftf.front().first == lf->get_open_options().loo_filename))
{
this->front_file = lf;
this->front_top = lnav_data.ld_files_to_front.front().second;
@@ -177,21 +189,26 @@ public:
}
}
+ void renamed_file(const std::shared_ptr<logfile>& lf) override
+ {
+ lnav_data.ld_active_files.regenerate_unique_file_names();
+ }
+
std::shared_ptr<logfile> front_file;
file_location_t front_top;
bool did_promotion{false};
};
-size_t
+rebuild_indexes_result_t
rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
{
logfile_sub_source& lss = lnav_data.ld_log_source;
textview_curses& log_view = lnav_data.ld_views[LNV_LOG];
textview_curses& text_view = lnav_data.ld_views[LNV_TEXT];
bool scroll_downs[LNV__MAX];
- size_t retval = 0;
+ rebuild_indexes_result_t retval;
- for (int lpc = 0; lpc < LNV__MAX; lpc++) {
+ for (auto lpc : {LNV_LOG, LNV_TEXT}) {
auto& view = lnav_data.ld_views[lpc];
if (view.is_selectable()) {
@@ -214,9 +231,13 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
auto* tss = &lnav_data.ld_text_source;
textfile_callback cb;
- if (tss->rescan_files(cb, deadline)) {
+ auto rescan_res = tss->rescan_files(cb, deadline);
+ if (rescan_res.rr_new_data) {
text_view.reload_data();
- retval += 1;
+ retval.rir_changes += rescan_res.rr_new_data;
+ }
+ if (!rescan_res.rr_scan_completed) {
+ retval.rir_completed = false;
}
if (cb.front_file != nullptr) {
@@ -250,8 +271,10 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
if (new_top_opt) {
log_info(" setting requested top line: %d",
(int) new_top_opt.value());
- text_view.set_top(new_top_opt.value());
+ text_view.set_selection(new_top_opt.value());
log_info(" actual top is now: %d", (int) text_view.get_top());
+ log_info(" actual selection is now: %d",
+ (int) text_view.get_selection());
scroll_downs[LNV_TEXT] = false;
} else {
log_warning("could not jump to requested line");
@@ -313,11 +336,12 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
for_each(pair.second.begin(),
pair.second.end(),
[&dupe_name](auto& lf) {
- log_info("Hiding duplicate file: %s",
- lf->get_filename().c_str());
- lf->mark_as_duplicate(dupe_name);
- lnav_data.ld_log_source.find_data(lf) |
- [](auto ld) { ld->set_visibility(false); };
+ if (lf->mark_as_duplicate(dupe_name)) {
+ log_info("Hiding duplicate file: %s",
+ lf->get_filename().c_str());
+ lnav_data.ld_log_source.find_data(lf) |
+ [](auto ld) { ld->set_visibility(false); };
+ }
});
reload = true;
}
@@ -327,10 +351,10 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
}
}
- retval += 1;
+ retval.rir_changes += 1;
}
- for (int lpc = 0; lpc < LNV__MAX; lpc++) {
+ for (auto lpc : {LNV_LOG, LNV_TEXT}) {
auto& scroll_view = lnav_data.ld_views[lpc];
if (scroll_downs[lpc]) {
@@ -348,9 +372,19 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
}
}
- lnav_data.ld_view_stack.top() | [](auto tc) {
- lnav_data.ld_filter_status_source.update_filtered(tc->get_sub_source());
- lnav_data.ld_scroll_broadcaster(tc);
+ lnav_data.ld_view_stack.top() | [&closed_files, &retval](auto tc) {
+ if (!closed_files.empty() && tc == &lnav_data.ld_views[LNV_GANTT]) {
+ auto* gantt_source = lnav_data.ld_views[LNV_GANTT].get_sub_source();
+ if (gantt_source != nullptr) {
+ gantt_source->text_filters_changed();
+ }
+ }
+
+ auto* tss = tc->get_sub_source();
+ lnav_data.ld_filter_status_source.update_filtered(tss);
+ if (retval.rir_changes > 0) {
+ lnav_data.ld_scroll_broadcaster(tc);
+ }
};
return retval;
@@ -359,7 +393,9 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
void
rebuild_indexes_repeatedly()
{
- for (size_t attempt = 0; attempt < 10 && rebuild_indexes() > 0; attempt++) {
+ for (size_t attempt = 0; attempt < 10 && rebuild_indexes().rir_changes > 0;
+ attempt++)
+ {
log_info("continuing to rebuild indexes...");
}
}
@@ -375,6 +411,9 @@ update_active_files(file_collection& new_files)
return true;
}
+ bool was_below_open_file_limit
+ = lnav_data.ld_active_files.is_below_open_file_limit();
+
for (const auto& lf : new_files.fc_files) {
lf->set_logfile_observer(&obs);
lnav_data.ld_text_source.push_back(lf);
@@ -389,11 +428,6 @@ update_active_files(file_collection& new_files)
}
}
lnav_data.ld_active_files.merge(new_files);
- if (!new_files.fc_files.empty() || !new_files.fc_other_files.empty()
- || !new_files.fc_name_to_errors.empty())
- {
- lnav_data.ld_active_files.regenerate_unique_file_names();
- }
lnav_data.ld_child_pollers.insert(
lnav_data.ld_child_pollers.begin(),
std::make_move_iterator(
@@ -409,6 +443,25 @@ update_active_files(file_collection& new_files)
};
});
+ if (was_below_open_file_limit
+ && !lnav_data.ld_active_files.is_below_open_file_limit())
+ {
+ auto um
+ = lnav::console::user_message::error("Unable to open more files")
+ .with_reason(
+ attr_line_t("The file-descriptor limit of ")
+ .append(lnav::roles::number(fmt::to_string(
+ file_collection::get_limits().l_fds)))
+ .append(" is too low to support opening more files"))
+ .with_help(
+ attr_line_t("Use ")
+ .append("ulimit -n"_quoted_code)
+ .append(
+ " to increase the limit before running lnav"));
+
+ lnav_data.ld_exec_context.ec_error_callback_stack.back()(um);
+ }
+
return true;
}
@@ -430,7 +483,9 @@ rescan_files(bool req)
continue;
}
- if (lnav_data.ld_active_files.fc_name_to_errors.count(pair.first)) {
+ if (lnav_data.ld_active_files.fc_name_to_errors->readAccess()
+ ->count(pair.first))
+ {
continue;
}
@@ -440,7 +495,8 @@ rescan_files(bool req)
all_synced = false;
}
}
- if (!lnav_data.ld_active_files.fc_name_to_errors.empty()) {
+ if (!lnav_data.ld_active_files.fc_name_to_errors->readAccess()->empty())
+ {
return false;
}
if (!all_synced) {