[logfile] prevent duplicate from being hidden a second time

Related to #1070
This commit is contained in:
Tim Stack 2023-10-10 12:20:49 -07:00
parent 68f97a6502
commit c92290e922
7 changed files with 37 additions and 22 deletions

View File

@ -97,6 +97,7 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch)
auto& lss = lnav_data.ld_log_source;
auto lf = *fs.sb_iter;
lf->set_indexing(true);
lss.find_data(lf) | [](auto ld) {
ld->set_visibility(true);
lnav_data.ld_log_source.text_filters_changed();
@ -136,6 +137,7 @@ files_sub_source::list_input_handle_key(listview_curses& lv, int ch)
auto lf = *fs.sb_iter;
lss.find_data(lf) | [](auto ld) {
ld->get_file_ptr()->set_indexing(!ld->ld_visible);
ld->set_visibility(!ld->ld_visible);
};

View File

@ -330,11 +330,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;
}
@ -373,9 +374,9 @@ rebuild_indexes(nonstd::optional<ui_clock::time_point> deadline)
}
}
auto* tss = tc->get_sub_source();
lnav_data.ld_filter_status_source.update_filtered(tss);
if (retval.rir_changes > 0) {
auto* tss = tc->get_sub_source();
lnav_data.ld_filter_status_source.update_filtered(tss);
lnav_data.ld_scroll_broadcaster(tc);
}
};

View File

@ -3321,8 +3321,10 @@ com_file_visibility(exec_context& ec,
if (only_this_file) {
for (const auto& ld : lnav_data.ld_log_source) {
ld->set_visibility(false);
ld->get_file_ptr()->set_indexing(false);
}
}
lf->set_indexing(make_visible);
lnav_data.ld_log_source.find_data(lf) |
[make_visible](auto ld) { ld->set_visibility(make_visible); };
tc->get_sub_source()->text_filters_changed();
@ -3375,6 +3377,7 @@ com_file_visibility(exec_context& ec,
if (!ec.ec_dry_run) {
ld_opt | [make_visible](auto ld) {
ld->get_file_ptr()->set_indexing(make_visible);
ld->set_visibility(make_visible);
};
}

View File

@ -1193,14 +1193,21 @@ logfile::find_from_time(const timeval& tv) const
return retval;
}
void
bool
logfile::mark_as_duplicate(const std::string& name)
{
safe::WriteAccess<safe_notes> notes(this->lf_notes);
auto iter = notes->find(note_type::duplicate);
if (iter != notes->end()) {
return false;
}
this->lf_indexing = false;
this->lf_options.loo_is_visible = false;
this->lf_notes.writeAccess()->emplace(
note_type::duplicate,
fmt::format(FMT_STRING("hiding duplicate of {}"), name));
notes->emplace(note_type::duplicate,
fmt::format(FMT_STRING("hiding duplicate of {}"), name));
return true;
}
void

View File

@ -195,7 +195,7 @@ public:
this->adjust_content_time(-1, tv);
}
void mark_as_duplicate(const std::string& name);
bool mark_as_duplicate(const std::string& name);
const logfile_open_options& get_open_options() const
{
@ -356,6 +356,8 @@ public:
bool is_indexing() const { return this->lf_indexing; }
void set_indexing(bool val) { this->lf_indexing = val; }
/** Check the invariants for this object. */
bool invariant()
{

View File

@ -926,16 +926,15 @@ load_session()
log_debug("found state for file: %s %d",
lf->get_content_id().c_str(),
iter->second.fs_is_visible);
lnav_data.ld_log_source.find_data(lf) | [iter](auto ld) {
ld->set_visibility(iter->second.fs_is_visible);
};
if (!iter->second.fs_is_visible) {
if (lf->get_format() != nullptr) {
log_changes = true;
} else {
text_changes = true;
}
}
lnav_data.ld_log_source.find_data(lf) |
[iter, &log_changes](auto ld) {
if (ld->ld_visible != iter->second.fs_is_visible) {
ld->get_file_ptr()->set_indexing(
iter->second.fs_is_visible);
ld->set_visibility(iter->second.fs_is_visible);
log_changes = true;
}
};
}
if (log_changes) {

View File

@ -1265,6 +1265,7 @@ CREATE TABLE lnav_view_files (
auto& ld = *iter;
if (ld->ld_visible != visible) {
ld->get_file_ptr()->set_indexing(visible);
ld->set_visibility(visible);
lss.text_filters_changed();
}