commit d3f0d32e162cbfa5ed89c0644873c68ce96184f0
parent 3f309bc36a4b831b941abcb30476571aa704d340
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 19 Nov 2018 12:00:18 +0100
rcfile: don't report an error when the globbing pattern matches nothing
Because a message like "Error expanding EMPTY/*.nanorc: Success"
looks silly.
Indirectly-reported-by: Ντέντος Σταύρος <stdedos@gmail.com>
(https://lists.gnu.org/archive/html/nano-devel/2018-11/msg00044.html)
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -542,19 +542,23 @@ void parse_includes(char *ptr)
char *was_nanorc = nanorc;
size_t was_lineno = lineno;
glob_t files;
+ int result;
pattern = ptr;
if (*pattern == '"')
pattern++;
ptr = parse_argument(ptr);
- /* Expand tildes first, then the globs. */
+ /* Expand a tilde first, then try to match the globbing pattern. */
expanded = real_dir_from_tilde(pattern);
+ result = glob(expanded, GLOB_ERR|GLOB_NOSORT, NULL, &files);
- if (glob(expanded, GLOB_ERR|GLOB_NOSORT, NULL, &files) == 0) {
+ /* If there are matches, process each of them. Otherwise, only
+ * report an error if it's something other than zero matches. */
+ if (result == 0) {
for (size_t i = 0; i < files.gl_pathc; ++i)
parse_one_include(files.gl_pathv[i]);
- } else
+ } else if (result != GLOB_NOMATCH)
rcfile_error(_("Error expanding %s: %s"), pattern, strerror(errno));
globfree(&files);