summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
1383481)
This removes duplication between the struct element and the
configuration string_map entry. Create a simple wrapper for setting
the database path that makes sure the trailing / is stripped.
void
_notmuch_config_cache (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val)
{
void
_notmuch_config_cache (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val)
{
+ if (notmuch->config == NULL)
+ notmuch->config = _notmuch_string_map_create (notmuch);
+
_notmuch_string_map_set (notmuch->config, _notmuch_config_key_to_string (key), val);
}
_notmuch_string_map_set (notmuch->config, _notmuch_config_key_to_string (key), val);
}
struct _notmuch_database {
bool exception_reported;
struct _notmuch_database {
bool exception_reported;
- /* Path to database parent directory and or/mail root */
- char *path;
-
/* Path to actual database */
const char *xapian_path;
/* Path to actual database */
const char *xapian_path;
const char *
notmuch_database_get_path (notmuch_database_t *notmuch)
{
const char *
notmuch_database_get_path (notmuch_database_t *notmuch)
{
+ return notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH);
+static void
+_set_database_path (notmuch_database_t *notmuch,
+ const char *database_path)
+{
+ char *path = talloc_strdup (notmuch, database_path);
+
+ strip_trailing (path, '/');
+
+ _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path);
+}
+
notmuch_status_t
notmuch_database_open_with_config (const char *database_path,
notmuch_database_mode_t mode,
notmuch_status_t
notmuch_database_open_with_config (const char *database_path,
notmuch_database_mode_t mode,
&key_file, &database_path, &message)))
goto DONE;
&key_file, &database_path, &message)))
goto DONE;
- notmuch->path = talloc_strdup (notmuch, database_path);
- strip_trailing (notmuch->path, '/');
+ _set_database_path (notmuch, database_path);
if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
message = strdup ("Out of memory\n");
if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
message = strdup ("Out of memory\n");