mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
lib/config: canonicalize paths relative to $HOME.
Prior to 0.32, notmuch had the (undocumented) behaviour that it expanded a relative value of database.path with respect to $HOME. In 0.32 this was special cased for database.path but broken for database.mail_root, which causes problems for at least notmuch-new when database.path is set to a relative path. The change in T030-config.sh reflects a user visible, but hopefully harmless behaviour change; the expanded form of the paths will now be printed by notmuch config.
This commit is contained in:
parent
ef0b126619
commit
31098c4ae4
3 changed files with 24 additions and 5 deletions
|
@ -387,6 +387,23 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs)
|
||||||
talloc_free (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_status_t
|
||||||
_notmuch_config_load_from_file (notmuch_database_t *notmuch,
|
_notmuch_config_load_from_file (notmuch_database_t *notmuch,
|
||||||
GKeyFile *file)
|
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);
|
keys = g_key_file_get_keys (file, *grp, NULL, NULL);
|
||||||
for (gchar **keys_p = keys; *keys_p; keys_p++) {
|
for (gchar **keys_p = keys; *keys_p; keys_p++) {
|
||||||
char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp, *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);
|
val = g_key_file_get_value (file, *grp, *keys_p, NULL);
|
||||||
if (! val) {
|
if (! val) {
|
||||||
status = NOTMUCH_STATUS_FILE_ERROR;
|
status = NOTMUCH_STATUS_FILE_ERROR;
|
||||||
goto DONE;
|
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);
|
g_free (val);
|
||||||
talloc_free (absolute_key);
|
talloc_free (absolute_key);
|
||||||
|
talloc_free (normalized_val);
|
||||||
if (status)
|
if (status)
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,12 +117,12 @@ test_expect_equal "$(notmuch config get database.path)" \
|
||||||
|
|
||||||
ln -s `pwd`/mail home/Maildir
|
ln -s `pwd`/mail home/Maildir
|
||||||
add_email_corpus
|
add_email_corpus
|
||||||
test_begin_subtest "Relative database path expanded in open"
|
test_begin_subtest "Relative database path expanded"
|
||||||
notmuch config set database.path Maildir
|
notmuch config set database.path Maildir
|
||||||
path=$(notmuch config get database.path)
|
path=$(notmuch config get database.path | notmuch_dir_sanitize)
|
||||||
count=$(notmuch count '*')
|
count=$(notmuch count '*')
|
||||||
test_expect_equal "${path} ${count}" \
|
test_expect_equal "${path} ${count}" \
|
||||||
"Maildir 52"
|
"CWD/home/Maildir 52"
|
||||||
|
|
||||||
test_begin_subtest "Add config to database"
|
test_begin_subtest "Add config to database"
|
||||||
notmuch new
|
notmuch new
|
||||||
|
|
|
@ -395,7 +395,6 @@ EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
test_begin_subtest "Relative database path expanded in new"
|
test_begin_subtest "Relative database path expanded in new"
|
||||||
test_subtest_known_broken
|
|
||||||
ln -s "$PWD/mail" home/Maildir
|
ln -s "$PWD/mail" home/Maildir
|
||||||
notmuch config set database.path Maildir
|
notmuch config set database.path Maildir
|
||||||
generate_message
|
generate_message
|
||||||
|
|
Loading…
Reference in a new issue