X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fopen.cc;h=6b717c1c13606de32e902f63b96a6718ecf82131;hb=8aeba1228ace947c1b689ae6ae08db5d53755917;hp=577fc88a40879267e9572e699ee904421cc959e6;hpb=ac67cd84eea1148680ab3a377d35ae346073f138;p=notmuch diff --git a/lib/open.cc b/lib/open.cc index 577fc88a..6b717c1c 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -68,6 +68,44 @@ _xdg_dir (void *ctx, profile_name); } +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, @@ -87,7 +125,7 @@ _load_key_file (const char *path, if (dir) { path = talloc_asprintf (local, "%s/config", dir); - if (access (path, R_OK) !=0) + if (access (path, R_OK) != 0) path = NULL; } } @@ -109,7 +147,7 @@ _load_key_file (const char *path, status = NOTMUCH_STATUS_NO_CONFIG; } -DONE: + DONE: talloc_free (local); return status; } @@ -123,7 +161,7 @@ _choose_database_path (const char *config_path, { notmuch_status_t status; - status =_load_key_file (config_path, profile, key_file); + status = _load_key_file (config_path, profile, key_file); if (status) { *message = strdup ("Error: cannot load config file.\n"); return status; @@ -148,7 +186,7 @@ notmuch_status_t notmuch_database_open_with_config (const char *database_path, notmuch_database_mode_t mode, const char *config_path, - unused(const char *profile), + const char *profile, notmuch_database_t **database, char **status_string) { @@ -281,8 +319,10 @@ notmuch_database_open_with_config (const char *database_path, notmuch->term_gen = new Xapian::TermGenerator; notmuch->term_gen->set_stemmer (Xapian::Stem ("english")); notmuch->value_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); - notmuch->date_range_processor = new ParseTimeRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, "date:"); - notmuch->last_mod_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); + notmuch->date_range_processor = new ParseTimeRangeProcessor (NOTMUCH_VALUE_TIMESTAMP, + "date:"); + notmuch->last_mod_range_processor = new Xapian::NumberRangeProcessor (NOTMUCH_VALUE_LAST_MOD, + "lastmod:"); notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); notmuch->query_parser->set_database (*notmuch->xapian_db); notmuch->query_parser->set_stemmer (Xapian::Stem ("english")); @@ -301,6 +341,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;