unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Cc: Tomi Ollila <tomi.ollila@iki.fi>, jani@nikula.org
Subject: [PATCH 2/2] notmuch-config: ENOENT vs generic handling when file open fails.
Date: Sun, 26 Feb 2017 21:12:39 +0200	[thread overview]
Message-ID: <20170226191239.30887-2-jani@nikula.org> (raw)
In-Reply-To: <20170226191239.30887-1-jani@nikula.org>

From: Tomi Ollila <tomi.ollila@iki.fi>

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 959410cce7b8..e4aaef610173 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.11.0

  reply	other threads:[~2017-02-26 19:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-26 19:12 [PATCH 1/2] cli/config: don't try to open config file for 'notmuch help' Jani Nikula
2017-02-26 19:12 ` Jani Nikula [this message]
2017-02-26 20:00 ` Tomi Ollila
2017-02-27 20:02 ` Tomi Ollila
2017-02-28 12:31 ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170226191239.30887-2-jani@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).