mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
cli: config: fix config file save when the file does not exist
The use of realpath(3) in
commit 58ed67992d
Author: Jani Nikula <jani@nikula.org>
Date: Sun Apr 7 20:15:03 2013 +0300
cli: config: do not overwrite symlinks when saving config file
broke config file save when the file does not exist, which results in
'notmuch setup' always failing to create a new config file.
Fix by checking ENOENT from realpath(3).
This commit is contained in:
parent
2c64c2e0eb
commit
9641fe1ce7
2 changed files with 13 additions and 5 deletions
|
@ -456,11 +456,20 @@ notmuch_config_save (notmuch_config_t *config)
|
|||
/* Try not to overwrite symlinks. */
|
||||
filename = realpath (config->filename, NULL);
|
||||
if (! filename) {
|
||||
if (errno == ENOENT) {
|
||||
filename = strdup (config->filename);
|
||||
if (! filename) {
|
||||
fprintf (stderr, "Out of memory.\n");
|
||||
g_free (data);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,
|
||||
strerror (errno));
|
||||
g_free (data);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (! g_file_set_contents (filename, data, length, &error)) {
|
||||
if (strcmp (filename, config->filename) != 0) {
|
||||
|
|
|
@ -4,7 +4,6 @@ test_description='"notmuch setup"'
|
|||
. ./test-lib.sh
|
||||
|
||||
test_begin_subtest "Create a new config interactively"
|
||||
test_subtest_known_broken
|
||||
notmuch --config=new-notmuch-config > /dev/null <<EOF
|
||||
Test Suite
|
||||
test.suite@example.com
|
||||
|
|
Loading…
Reference in a new issue