Currently the only checked failure is HOME being unset. In some places
this introduces new error paths, but no new error status values.
---
lib/open.cc | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/lib/open.cc b/lib/open.cc
index b9e186ce..cdee23fd 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -44,14 +44,21 @@ static const char *
_xdg_dir (void *ctx,
const char *xdg_root_variable,
const char *xdg_prefix,
- const char *profile_name)
+ const char *profile_name,
+ char **message)
{
const char *xdg_root = getenv (xdg_root_variable);
if (! xdg_root) {
const char *home = getenv ("HOME");
- if (! home) return NULL;
+ if (! home) {
+ if (message)
+ IGNORE_RESULT(asprintf (message,
+ "Error: %s and HOME both unset, XDG path undefined\n",
+ xdg_root_variable));
+ return NULL;
+ }
xdg_root = talloc_asprintf (ctx,
"%s/%s",
@@ -90,7 +97,7 @@ _choose_dir (notmuch_database_t *notmuch,
if (dir)
return NOTMUCH_STATUS_SUCCESS;
- parent = _xdg_dir (notmuch, xdg_var, xdg_subdir, profile);
+ parent = _xdg_dir (notmuch, xdg_var, xdg_subdir, profile, message);
if (! parent)
return NOTMUCH_STATUS_PATH_ERROR;
@@ -130,7 +137,7 @@ _load_key_file (notmuch_database_t *notmuch,
if (path)
path = talloc_strdup (notmuch, path);
else {
- const char *dir = _xdg_dir (notmuch, "XDG_CONFIG_HOME", ".config", profile);
+ const char *dir = _xdg_dir (notmuch, "XDG_CONFIG_HOME", ".config", profile, NULL);
if (dir) {
path = talloc_asprintf (notmuch, "%s/config", dir);
@@ -210,7 +217,10 @@ _choose_database_path (notmuch_database_t *notmuch,
}
}
if (! *database_path) {
- *database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile);
+ *database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile, message);
+ if (! database_path)
+ return NOTMUCH_STATUS_PATH_ERROR;
+
status = _db_dir_exists (*database_path, message);
if (status) {
*database_path = NULL;
@@ -293,7 +303,10 @@ _create_database_path (notmuch_database_t *notmuch,
}
if (! *database_path) {
- *database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile);
+ *database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile, message);
+ if (*database_path == NULL)
+ return NOTMUCH_STATUS_PATH_ERROR;
+
notmuch->params |= NOTMUCH_PARAM_SPLIT;
}
--
2.53.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org