1
1
mirror of https://github.com/tstack/lnav.git synced 2024-09-11 13:05:51 +03:00

[open] add some more checks when opening a file

This commit is contained in:
Timothy Stack 2014-03-12 08:44:02 -07:00
parent 365f8c619a
commit 7b1bb506e2
2 changed files with 22 additions and 1 deletions

View File

@ -878,11 +878,19 @@ static string com_open(string cmdline, vector<string> &args)
retval = "info: watching -- " + fn;
}
else if (stat(fn.c_str(), &st) == -1) {
retval = "error: cannot stat file: " + fn + " " + strerror(errno);
retval = ("error: cannot stat file: " + fn + " -- "
+ strerror(errno));
}
else if ((abspath = realpath(fn.c_str(), NULL)) == NULL) {
retval = "error: cannot find file";
}
else if (!S_ISREG(st.st_mode)) {
retval = "error: not a regular file";
}
else if (access(fn.c_str(), R_OK) == -1) {
retval = (string("error: cannot read file -- ") +
strerror(errno));
}
else {
fn = abspath.in();
lnav_data.ld_file_names.insert(make_pair(fn, -1));

View File

@ -98,6 +98,19 @@ check_output "open is not working" <<EOF
EOF
run_test ${lnav_test} -n \
-c ":close" \
-c ":open /" \
${test_dir}/logfile_access_log.0
check_error_output "open dir is working" <<EOF
error: not a regular file
EOF
check_output "open dir is not working" <<EOF
EOF
run_test ${lnav_test} -n \
-c ";select * from access_log" \
-c ':write-json-to -' \