X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fconfig.cc;fp=lib%2Fconfig.cc;h=abdc19c3de000b610d57f9f98d71127a51797f7f;hb=31098c4ae40511ffda9788a6654adbf898063d7f;hp=50bcf6a28c43037099a616af432081aa25018658;hpb=ef0b1266190141b108a338ba06348e335ec4957b;p=notmuch diff --git a/lib/config.cc b/lib/config.cc index 50bcf6a2..abdc19c3 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -387,6 +387,23 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs) talloc_free (pairs); } +static char * +_expand_path (void *ctx, const char *key, const char *val) +{ + char *expanded_val; + + if ((strcmp (key, "database.path") == 0 || + strcmp (key, "database.mail_root") == 0 || + strcmp (key, "database.hook_dir") == 0 || + strcmp (key, "database.backup_path") == 0 ) && + val[0] != '/') + expanded_val = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), val); + else + expanded_val = talloc_strdup (ctx, val); + + return expanded_val; +} + notmuch_status_t _notmuch_config_load_from_file (notmuch_database_t *notmuch, GKeyFile *file) @@ -407,14 +424,17 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, keys = g_key_file_get_keys (file, *grp, NULL, NULL); for (gchar **keys_p = keys; *keys_p; keys_p++) { char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp, *keys_p); + char *normalized_val; val = g_key_file_get_value (file, *grp, *keys_p, NULL); if (! val) { status = NOTMUCH_STATUS_FILE_ERROR; goto DONE; } - _notmuch_string_map_set (notmuch->config, absolute_key, val); + normalized_val = _expand_path (notmuch, absolute_key, val); + _notmuch_string_map_set (notmuch->config, absolute_key, normalized_val); g_free (val); talloc_free (absolute_key); + talloc_free (normalized_val); if (status) goto DONE; }