summaryrefslogtreecommitdiffstats
path: root/src/file_vtab.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/file_vtab.cc58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/file_vtab.cc b/src/file_vtab.cc
index aab5d5b..7fb9bde 100644
--- a/src/file_vtab.cc
+++ b/src/file_vtab.cc
@@ -40,6 +40,9 @@
#include "logfile.hh"
#include "session_data.hh"
#include "vtab_module.hh"
+#include "vtab_module_json.hh"
+
+namespace {
struct lnav_file : public tvt_iterator_cursor<lnav_file> {
using iterator = std::vector<std::shared_ptr<logfile>>::iterator;
@@ -56,6 +59,8 @@ CREATE TABLE lnav_file (
format text, -- The log file format for the file.
lines integer, -- The number of lines in the file.
time_offset integer, -- The millisecond offset for timestamps.
+ options_path TEXT, -- The matched path for the file options.
+ options TEXT, -- The effective options for the file.
content BLOB HIDDEN -- The contents of the file.
);
@@ -108,6 +113,36 @@ CREATE TABLE lnav_file (
break;
}
case 8: {
+ if (sqlite3_vtab_nochange(ctx)) {
+ return SQLITE_OK;
+ }
+
+ auto opts = lf->get_file_options();
+ if (opts) {
+ to_sqlite(ctx, opts.value().first);
+ } else {
+ sqlite3_result_null(ctx);
+ }
+ break;
+ }
+ case 9: {
+ if (sqlite3_vtab_nochange(ctx)) {
+ return SQLITE_OK;
+ }
+
+ auto opts = lf->get_file_options();
+ if (opts) {
+ to_sqlite(ctx, opts.value().second.to_json_string());
+ } else {
+ sqlite3_result_null(ctx);
+ }
+ break;
+ }
+ case 10: {
+ if (sqlite3_vtab_nochange(ctx)) {
+ return SQLITE_OK;
+ }
+
auto& cfg = injector::get<const file_vtab::config&>();
auto lf_stat = lf->get_stat();
@@ -115,8 +150,7 @@ CREATE TABLE lnav_file (
sqlite3_result_error(ctx, "file is too large", -1);
} else {
auto fd = lf->get_fd();
- auto_mem<char> buf;
- buf = (char*) malloc(lf_stat.st_size);
+ auto buf = auto_mem<char>::malloc(lf_stat.st_size);
auto rc = pread(fd, buf, lf_stat.st_size, 0);
if (rc == -1) {
@@ -183,6 +217,8 @@ CREATE TABLE lnav_file (
const char* format,
int64_t lines,
int64_t time_offset,
+ const char* options_path,
+ const char* options,
const char* content)
{
auto lf = this->lf_collection.fc_files[rowid];
@@ -203,18 +239,20 @@ CREATE TABLE lnav_file (
= this->lf_collection.fc_file_names.find(lf->get_filename());
if (iter != this->lf_collection.fc_file_names.end()) {
- auto loo = std::move(iter->second);
+ auto loo = iter->second;
this->lf_collection.fc_file_names.erase(iter);
loo.loo_include_in_session = true;
- this->lf_collection.fc_file_names[path] = std::move(loo);
- lf->set_filename(path);
- this->lf_collection.regenerate_unique_file_names();
-
- init_session();
- load_session();
+ this->lf_collection.fc_file_names[path] = loo;
}
+
+ lf->set_filename(path);
+ lf->set_include_in_session(true);
+ this->lf_collection.regenerate_unique_file_names();
+
+ init_session();
+ load_session();
}
return SQLITE_OK;
@@ -343,3 +381,5 @@ static auto file_binder
static auto file_meta_binder = injector::bind_multiple<vtab_module_base>()
.add<injectable_lnav_file_metadata>();
+
+} // namespace