[fstab_vtab] add "data" column to the table

Bump rapidyaml version
pull/1205/head
Tim Stack 10 months ago
parent 01c973868d
commit 862079e663

@ -83,6 +83,8 @@ Features:
- `/ui/theme-defs/<theme_name>/syntax-styles/separators-references-accessors`
* Multi-line block comments (i.e. `/* ... */`) and strings
are now recognized and styled as appropriate.
* Added a `data` column to the `fstat()` table-valued-
function so the contents of a file can be read.
Bug Fixes:
* Binary data piped into stdin should now be treated the same

@ -36,10 +36,12 @@
#include <sys/stat.h>
#include "base/auto_mem.hh"
#include "base/fs_util.hh"
#include "base/injector.hh"
#include "base/lnav_log.hh"
#include "bound_tags.hh"
#include "config.h"
#include "ghc/filesystem.hpp"
#include "sql_util.hh"
#include "vtab_module.hh"
@ -63,6 +65,7 @@ enum {
FSTAT_COL_MTIME,
FSTAT_COL_CTIME,
FSTAT_COL_PATTERN,
FSTAT_COL_DATA,
};
/**
@ -90,7 +93,8 @@ CREATE TABLE fstat (
st_atime DATETIME,
st_mtime DATETIME,
st_ctime DATETIME,
pattern TEXT HIDDEN
pattern TEXT HIDDEN,
data BLOB HIDDEN
);
)";
@ -253,6 +257,45 @@ CREATE TABLE fstat (
vc.c_pattern.length(),
SQLITE_TRANSIENT);
break;
case FSTAT_COL_DATA: {
auto fs_path = ghc::filesystem::path{path};
if (S_ISREG(vc.c_stat.st_mode)) {
auto open_res
= lnav::filesystem::open_file(fs_path, O_RDONLY);
if (open_res.isErr()) {
log_error("unable to read file: %s -- %s",
path,
open_res.unwrapErr().c_str());
sqlite3_result_null(ctx);
} else {
auto buffer = auto_buffer::alloc(vc.c_stat.st_size);
auto fd = open_res.unwrap();
while (true) {
if (buffer.available() == 0) {
buffer.expand_by(4096);
}
auto rc = read(fd,
buffer.next_available(),
buffer.available());
if (rc <= 0) {
break;
}
buffer.resize_by(rc);
}
to_sqlite(ctx, blob_auto_buffer{std::move(buffer)});
}
} else if (S_ISLNK(vc.c_stat.st_mode)) {
auto link_path = ghc::filesystem::read_symlink(fs_path);
to_sqlite(ctx, link_path.string());
} else {
sqlite3_result_null(ctx);
}
break;
}
}
return SQLITE_OK;

@ -0,0 +1,15 @@
#
# @synopsis: docker-compose-url-handler
# @description: Internal script to handle opening docker-compose URLs
#
;SELECT st_name FROM fstat('compose.yml')
UNION
SELECT st_name FROM fstat('compose.yaml')
UNION
SELECT st_name FROM fstat('docker-compose.yml')
UNION
SELECT st_name FROM fstat('docker-compose.yaml')
;SELECT group_concat(compose_services.key, ' ')
FROM fstat($st_name), json_each(yaml_to_json(data), '$.services') as compose_services

@ -2,6 +2,7 @@
BUILTIN_LNAVSCRIPTS = \
$(srcdir)/scripts/dhclient-summary.lnav \
$(srcdir)/scripts/docker-url-handler.lnav \
$(srcdir)/scripts/docker-compose-url-handler.lnav \
$(srcdir)/scripts/lnav-pop-view.lnav \
$(srcdir)/scripts/partition-by-boot.lnav \
$(srcdir)/scripts/piper-url-handler.lnav \

File diff suppressed because it is too large Load Diff

@ -698,6 +698,14 @@ struct json_string {
memcpy((void*) this->js_content.in(), buf, this->js_len);
}
explicit json_string(auto_buffer&& buf)
{
auto buf_pair = buf.release();
this->js_content = (const unsigned char*) buf_pair.first;
this->js_len = buf_pair.second;
}
auto_mem<const unsigned char> js_content;
size_t js_len{0};
};

@ -36,6 +36,7 @@
#include "ryml_all.hpp"
#include "sqlite-extension-func.hh"
#include "vtab_module.hh"
#include "vtab_module_json.hh"
using namespace lnav::roles::literals;
@ -56,7 +57,7 @@ ryml_error_to_um(const char* msg, size_t len, ryml::Location loc, void* ud)
source_location{src, (int32_t) loc.line}, ""));
}
static text_auto_buffer
static json_string
yaml_to_json(string_fragment in)
{
ryml::Callbacks callbacks(&in, nullptr, nullptr, ryml_error_to_um);
@ -74,7 +75,7 @@ yaml_to_json(string_fragment in)
ryml::substr(buf.in(), buf.size()),
/*error_on_excess*/ true);
return {std::move(buf)};
return json_string{std::move(buf)};
}
int

Loading…
Cancel
Save