mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
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.
This commit is contained in:
parent
80aeaf7f59
commit
5c0f1bd367
1 changed files with 14 additions and 15 deletions
|
@ -215,24 +215,23 @@ get_config_from_file (notmuch_config_t *config, notmuch_bool_t create_new)
|
||||||
|
|
||||||
FILE *fp = fopen(config->filename, "r");
|
FILE *fp = fopen(config->filename, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
/* If create_new is true, then the caller is prepared for a
|
if (errno == ENOENT) {
|
||||||
* default configuration file in the case of FILE NOT FOUND.
|
/* 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;
|
if (create_new) {
|
||||||
ret = TRUE;
|
config->is_new = TRUE;
|
||||||
goto out;
|
ret = TRUE;
|
||||||
} else if (errno == ENOENT) {
|
} else {
|
||||||
fprintf (stderr, "Configuration file %s not found.\n"
|
fprintf (stderr, "Configuration file %s not found.\n"
|
||||||
"Try running 'notmuch setup' to create a configuration.\n",
|
"Try running 'notmuch setup' to create a configuration.\n",
|
||||||
config->filename);
|
config->filename);
|
||||||
goto out;
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr, "Error opening config file '%s': %s\n"
|
fprintf (stderr, "Error opening config file '%s': %s\n",
|
||||||
"Try running 'notmuch setup' to create a configuration.\n",
|
|
||||||
config->filename, strerror(errno));
|
config->filename, strerror(errno));
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
config_str = talloc_zero_array (config, char, config_bufsize);
|
config_str = talloc_zero_array (config, char, config_bufsize);
|
||||||
|
|
Loading…
Reference in a new issue