aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-01-09 15:05:58 -0400
committerDavid Bremner <david@tethera.net>2021-02-06 19:56:13 -0400
commit0345bc57a0d00d576c0e8bccc23fd448736a4511 (patch)
treea83fba9bac8eae44a7a3904cd7e5d0c7b669e94a /lib
parent4922416cccb826483e8306461a15a7372e97d3ce (diff)
lib/open: set HOOK_DIR on open
This is a simple two step path search. Most error checking is deferred until running the hooks.
Diffstat (limited to 'lib')
-rw-r--r--lib/open.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/open.cc b/lib/open.cc
index 577fc88a..b4637ec5 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -69,6 +69,44 @@ _xdg_dir (void *ctx,
}
static notmuch_status_t
+_choose_hook_dir (notmuch_database_t *notmuch,
+ const char *profile,
+ char **message)
+{
+ const char *config;
+ const char *hook_dir;
+ struct stat st;
+ int err;
+
+ hook_dir = notmuch_config_get (notmuch, NOTMUCH_CONFIG_HOOK_DIR);
+
+ if (hook_dir)
+ return NOTMUCH_STATUS_SUCCESS;
+
+ config = _xdg_dir (notmuch, "XDG_CONFIG_HOME", ".config", profile);
+ if (! config)
+ return NOTMUCH_STATUS_PATH_ERROR;
+
+ hook_dir = talloc_asprintf (notmuch, "%s/hooks", config);
+
+ err = stat (hook_dir, &st);
+ if (err) {
+ if (errno == ENOENT) {
+ const char *database_path = notmuch_database_get_path (notmuch);
+ hook_dir = talloc_asprintf (notmuch, "%s/.notmuch/hooks", database_path);
+ } else {
+ IGNORE_RESULT (asprintf (message, "Error: Cannot stat %s: %s.\n",
+ hook_dir, strerror (errno)));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+ }
+
+ _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_HOOK_DIR, hook_dir);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+static notmuch_status_t
_load_key_file (const char *path,
const char *profile,
GKeyFile **key_file)
@@ -301,6 +339,10 @@ notmuch_database_open_with_config (const char *database_path,
if (status)
goto DONE;
+ status = _choose_hook_dir (notmuch, profile, &message);
+ if (status)
+ goto DONE;
+
status = _notmuch_config_load_defaults (notmuch);
if (status)
goto DONE;