From 78d80fddd5aa2cf2d1bfec62fb96dc3ccdfe5d6c Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Thu, 14 Mar 2019 22:24:57 -0700 Subject: [PATCH] [cli] add -r flag for recursively loading files from a directory hierarchy Fixes #431 --- NEWS | 2 ++ lnav.1 | 3 +++ release/Makefile | 2 +- src/help.txt | 3 ++- src/lnav.cc | 22 +++++++++++++++++++--- src/lnav.hh | 2 ++ test/expected_help.txt | 3 ++- 7 files changed, 31 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 33153fd6..b211210d 100644 --- a/NEWS +++ b/NEWS @@ -42,6 +42,8 @@ lnav v0.8.5: you can press TAB cycle through the options. * Added CTRL+F to toggle the enabled/disabled state of all filters for the current view. + * The '-r' flag is now for recursively loading files. The functionality + for loading rotated files is now under the '-R' flag. * The current search term is now shown in the bottom status bar. * Some initial help text is now shown for the search and SQL prompts to refresh the memory. diff --git a/lnav.1 b/lnav.1 index 494f2ac6..c22d1401 100644 --- a/lnav.1 +++ b/lnav.1 @@ -71,6 +71,9 @@ Print version information. Load all of the most recent log file types. .TP \fB\-r\fR +Recursively load files from the given directories. +.TP +\fB\-R\fR Load older rotated log files as well. .TP \fB\-t\fR diff --git a/release/Makefile b/release/Makefile index bb1821f9..6e4125b2 100644 --- a/release/Makefile +++ b/release/Makefile @@ -16,7 +16,7 @@ PACKAGE_URLS = \ https://ftp.gnu.org/gnu/readline/readline-6.3.tar.gz \ http://www.zlib.net/zlib-1.2.11.tar.gz \ http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz \ - https://sqlite.org/2018/sqlite-autoconf-3260000.tar.gz \ + https://sqlite.org/2019/sqlite-autoconf-3270200.tar.gz \ https://www.openssl.org/source/openssl-1.0.2n.tar.gz \ https://www.libssh2.org/download/libssh2-1.8.0.tar.gz \ https://curl.haxx.se/download/curl-7.63.0.tar.gz diff --git a/src/help.txt b/src/help.txt index bee53358..85637289 100644 --- a/src/help.txt +++ b/src/help.txt @@ -36,7 +36,8 @@ arguments to load well-known log files, such as the syslog or apache log files. The flag arguments are: -a Load all of the most recent log file types. - -r Load older rotated log files as well. + -r Recursively load files from the given directory hierarchies. + -R Load older rotated log files as well. When using the flag arguments, lnav will look for the files relative to the current directory and its parent directories. In other words, diff --git a/src/lnav.cc b/src/lnav.cc index fbd0a614..82fa5f5d 100644 --- a/src/lnav.cc +++ b/src/lnav.cc @@ -825,7 +825,8 @@ static void usage() " -V Print version information.\n" "\n" " -a Load all of the most recent log file types.\n" - " -r Load older rotated log files as well.\n" + " -r Recursively load files from the given directory hierarchies.\n" + " -R Load older rotated log files as well.\n" " -t Prepend timestamps to the lines of data being read in\n" " on the standard input.\n" " -w file Write the contents of the standard input to this file.\n" @@ -915,6 +916,17 @@ static bool watch_logfile(string filename, logfile_open_options &loo, bool requi } if (rc == 0) { + if (S_ISDIR(st.st_mode) && lnav_data.ld_flags & LNF_RECURSIVE) { + string wilddir = filename + "/*"; + + if (lnav_data.ld_file_names.find(wilddir) == + lnav_data.ld_file_names.end()) { + logfile_open_options default_loo; + + lnav_data.ld_file_names[wilddir] = default_loo; + } + return retval; + } if (!S_ISREG(st.st_mode)) { if (required) { rc = -1; @@ -1843,7 +1855,7 @@ int main(int argc, char *argv[]) #endif lnav_data.ld_debug_log_name = "/dev/null"; - while ((c = getopt(argc, argv, "hHarCc:I:iuf:d:nqtw:vVW")) != -1) { + while ((c = getopt(argc, argv, "hHarRCc:I:iuf:d:nqtw:vVW")) != -1) { switch (c) { case 'h': usage(); @@ -1924,10 +1936,14 @@ int main(int argc, char *argv[]) lnav_data.ld_flags |= LNF_QUIET; break; - case 'r': + case 'R': lnav_data.ld_flags |= LNF_ROTATED; break; + case 'r': + lnav_data.ld_flags |= LNF_RECURSIVE; + break; + case 't': lnav_data.ld_flags |= LNF_TIMESTAMP; break; diff --git a/src/lnav.hh b/src/lnav.hh index 5f91fedd..58a0ae47 100644 --- a/src/lnav.hh +++ b/src/lnav.hh @@ -89,6 +89,7 @@ enum { LNB_HEADLESS, LNB_QUIET, LNB_ROTATED, + LNB_RECURSIVE, LNB_CHECK_CONFIG, LNB_INSTALL, LNB_UPDATE_FORMATS, @@ -101,6 +102,7 @@ typedef enum { LNF_SYSLOG = (1L << LNB_SYSLOG), LNF_ROTATED = (1L << LNB_ROTATED), + LNF_RECURSIVE = (1L << LNB_RECURSIVE), LNF_TIMESTAMP = (1L << LNB_TIMESTAMP), LNF_HELP = (1L << LNB_HELP), diff --git a/test/expected_help.txt b/test/expected_help.txt index 60071517..2ddca7ad 100644 --- a/test/expected_help.txt +++ b/test/expected_help.txt @@ -36,7 +36,8 @@ arguments to load well-known log files, such as the syslog or apache log files. The flag arguments are: -a Load all of the most recent log file types. - -r Load older rotated log files as well. + -r Recursively load files from the given directory hierarchies. + -R Load older rotated log files as well. When using the flag arguments, lnav will look for the files relative to the current directory and its parent directories. In other words,