[open] handle file names with colons

Fixes #863
This commit is contained in:
Timothy Stack 2021-06-07 16:04:41 -07:00
parent 408a2ea38e
commit b2d296b5d3
9 changed files with 64 additions and 14 deletions

View File

@ -150,6 +150,7 @@ should be another object with the following fields:
:%L: Milliseconds as a decimal number (range 000 to 999).
:%f: Microseconds as a decimal number (range 000000 to 999999).
:%N: Nanoseconds as a decimal number (range 000000000 to 999999999).
:%q: Seconds from the epoch as a hexidecimal number.
:%i: Milliseconds from the epoch.
:%6: Microseconds from the epoch.

View File

@ -379,7 +379,7 @@ void file_collection::expand_filename(lnav::futures::future_queue<file_collectio
}
auto rp_opt = humanize::network::path::from_str(path);
if (rp_opt) {
if (rp_opt && access(path.c_str(), R_OK) == -1) {
auto iter = this->fc_other_files.find(path);
auto rp = *rp_opt;

View File

@ -449,14 +449,15 @@ static void sql_json_group_object_step(sqlite3_context *context,
context, sizeof(json_agg_context));
if (jac->jac_yajl_gen == NULL) {
jac->jac_yajl_gen = yajl_gen_alloc(NULL);
if (jac->jac_yajl_gen == nullptr) {
jac->jac_yajl_gen = yajl_gen_alloc(nullptr);
yajl_gen_config(jac->jac_yajl_gen, yajl_gen_beautify, false);
yajl_gen_map_open(jac->jac_yajl_gen);
}
for (int lpc = 0; (lpc + 1) < argc; lpc += 2) {
log_debug("arg type %d", sqlite3_value_type(argv[lpc]));
if (sqlite3_value_type(argv[lpc]) == SQLITE_NULL) {
continue;
}

View File

@ -2540,16 +2540,21 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
});
}
#endif
else if (is_glob(argv[lpc]) || strchr(argv[lpc], ':') != nullptr) {
else if (is_glob(argv[lpc])) {
lnav_data.ld_active_files.fc_file_names[argv[lpc]]
.with_tail(!(lnav_data.ld_flags & LNF_HEADLESS));
}
else if (stat(argv[lpc], &st) == -1) {
fprintf(stderr,
"Cannot stat file: %s -- %s\n",
argv[lpc],
strerror(errno));
retval = EXIT_FAILURE;
if (strchr(argv[lpc], ':') != nullptr) {
lnav_data.ld_active_files.fc_file_names[argv[lpc]]
.with_tail(!(lnav_data.ld_flags & LNF_HEADLESS));
} else {
fprintf(stderr,
"Cannot stat file: %s -- %s\n",
argv[lpc],
strerror(errno));
retval = EXIT_FAILURE;
}
}
else if (access(argv[lpc], R_OK) == -1) {
fprintf(stderr,

View File

@ -2189,13 +2189,18 @@ static Result<string, string> com_open(exec_context &ec, string cmdline, vector<
}
#endif
}
else if (is_glob(fn.c_str()) || fn.find(':') != string::npos) {
else if (is_glob(fn.c_str())) {
file_names.emplace(fn, logfile_open_options());
retval = "info: watching -- " + fn;
}
else if (stat(fn.c_str(), &st) == -1) {
return ec.make_error("cannot stat file: {} -- {}", fn,
strerror(errno));
if (fn.find(':') != string::npos) {
file_names.emplace(fn, logfile_open_options());
retval = "info: watching -- " + fn;
} else {
return ec.make_error("cannot stat file: {} -- {}", fn,
strerror(errno));
}
}
else if (is_dev_null(st)) {
return ec.make_error("cannot open /dev/null");

View File

@ -23,6 +23,19 @@ info: load preview request -- 1234
info: exiting...
EOF
run_test ./drive_tailer preview ${test_dir}/remote-log-dir
check_output "preview of file failed?" <<EOF
preview of file: {test_dir}/remote-log-dir
logfile_access_log.0
logfile_access_log.1
all done!
tailer stderr:
info: load preview request -- 1234
info: exiting...
EOF
run_test ./drive_tailer possible "${test_dir}/logfile_access_log.*"
check_output "possible path list failed?" <<EOF

View File

@ -417,6 +417,7 @@ DISTCLEANFILES = \
logfile_syslog_test.2 \
logfile_syslog_fr_test.0 \
logfile_syslog_with_mixed_times_test.0 \
not:a:remote:file \
test-logs.tgz \
test-logs-trunc.tgz \
test_pretty_in.* \

View File

@ -1,5 +1,22 @@
#! /bin/bash
echo "Hello, World!" > not:a:remote:file
run_test ${lnav_test} -d /tmp/lnav.err -n \
not:a:remote:file
check_output "a file with colons cannot be read?" <<EOF
Hello, World!
EOF
run_test ${lnav_test} -d /tmp/lnav.err -Nn \
-c ':open not:a:remote:file'
check_output "a file with colons cannot be read?" <<EOF
Hello, World!
EOF
export HOME=${PWD}/remote
rm -rf remote-tmp

View File

@ -1,10 +1,17 @@
#! /bin/bash
run_test ./drive_sql "select json_concat(NULL, 1.0, 2.0)"
run_test ./drive_sql "select json_concat(json('[null, true, 0]'), 1.0, 2.0)"
check_output "json_concat does not work" <<EOF
Row 0:
Column json_concat(NULL, 1.0, 2.0): [1.0,2.0]
Column json_concat(json('[null, true, 0]'), 1.0, 2.0): [null,true,0,1.0,2.0]
EOF
run_test ./drive_sql "select json_concat(json('[\"tag0\"]'), 'tag1', 'tag2')"
check_output "json_concat does not work with strings" <<EOF
Row 0:
Column json_concat(json('["tag0"]'), 'tag1', 'tag2'): ["tag0","tag1","tag2"]
EOF
run_test ./drive_sql "select json_concat(NULL, NULL)"