aboutsummaryrefslogtreecommitdiff
path: root/notmuch-config.c
diff options
context:
space:
mode:
authorTomi Ollila <tomi.ollila@iki.fi>2017-02-26 21:12:39 +0200
committerDavid Bremner <david@tethera.net>2017-02-28 08:08:26 -0400
commit5c0f1bd36790e680f7d3b6082e3606bd3b84a588 (patch)
tree22c4d8773a8035e6347c77a8e16a265261ac4e30 /notmuch-config.c
parent80aeaf7f59e250f034ecc99aa7fcd1e6dd14d9bb (diff)
notmuch-config: ENOENT vs generic handling when file open fails.
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.
Diffstat (limited to 'notmuch-config.c')
-rw-r--r--notmuch-config.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index 959410cc..e4aaef61 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);