[PATCH 2/2] cli: config: fix config file save when the file does not exist
Jani Nikula
jani at nikula.org
Sun May 5 12:18:20 PDT 2013
The use of realpath(3) in
commit 58ed67992d0ec1fa505026105218fa449f7980b0
Author: Jani Nikula <jani at 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).
---
notmuch-config.c | 17 +++++++++++++----
test/setup | 1 -
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index d9c2eb3..befe9b5 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -456,10 +456,19 @@ notmuch_config_save (notmuch_config_t *config)
/* Try not to overwrite symlinks. */
filename = realpath (config->filename, NULL);
if (! filename) {
- fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,
- strerror (errno));
- g_free (data);
- return 1;
+ 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)) {
diff --git a/test/setup b/test/setup
index 8cc5576..124ef1c 100755
--- a/test/setup
+++ b/test/setup
@@ -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 at example.com
--
1.7.10.4
More information about the notmuch
mailing list