[PATCH] notmuch-config: ENOENT vs generic handling when file open fails.

Subject: [PATCH] notmuch-config: ENOENT vs generic handling when file open fails.

Date: Thu, 5 Jan 2017 00:52:12 +0200

To: notmuch@notmuchmail.org

Cc: tomi.ollila@iki.fi

From: Tomi Ollila


When opening configuration file fails, ENOENT (file not found) is
handled specially -- in setup missing file is ok (often expected),
and otherwise user can be informed to run notmuch setup.

In any other case the the reason is unknown, so there is no other
option but to print generic error message to stderr.
---
 notmuch-config.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/notmuch-config.c b/notmuch-config.c
index cdb4088d1535..baead520096b 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -215,24 +215,23 @@ get_config_from_file (notmuch_config_t *config, notmuch_bool_t create_new)
 
     FILE *fp = fopen(config->filename, "r");
     if (fp == NULL) {
-	/* If create_new is true, then the caller is prepared for a
-	 * default configuration file in the case of FILE NOT FOUND.
-	 */
-	if (create_new) {
-	    config->is_new = TRUE;
-	    ret = TRUE;
-	    goto out;
-	} else if (errno == ENOENT) {
-	    fprintf (stderr, "Configuration file %s not found.\n"
-		     "Try running 'notmuch setup' to create a configuration.\n",
-		     config->filename);
-	    goto out;
+	if (errno == ENOENT) {
+	    /* If create_new is true, then the caller is prepared for a
+	     * default configuration file in the case of FILE NOT FOUND.
+	     */
+	    if (create_new) {
+		config->is_new = TRUE;
+		ret = TRUE;
+	    } else {
+		fprintf (stderr, "Configuration file %s not found.\n"
+			 "Try running 'notmuch setup' to create a configuration.\n",
+			 config->filename);
+	    }
 	} else {
-	    fprintf (stderr, "Error opening config file '%s': %s\n"
-		     "Try running 'notmuch setup' to create a configuration.\n",
+	    fprintf (stderr, "Error opening config file '%s': %s\n",
 		     config->filename, strerror(errno));
-	    goto out;
 	}
+	goto out;
     }
 
     config_str = talloc_zero_array (config, char, config_bufsize);
-- 
2.8.2


Thread: