From d3f0d32e162cbfa5ed89c0644873c68ce96184f0 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 19 Nov 2018 12:00:18 +0100 Subject: [PATCH] rcfile: don't report an error when the globbing pattern matches nothing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because a message like "Error expanding EMPTY/*.nanorc: Success" looks silly. Indirectly-reported-by: Ντέντος Σταύρος (https://lists.gnu.org/archive/html/nano-devel/2018-11/msg00044.html) --- src/rcfile.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index f322e7fc..3ddeb67e 100644 --- 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);