]> git.cworth.org Git - obsolete/notmuch-old/commitdiff
cli: config: fix config file save when the file does not exist
authorJani Nikula <jani@nikula.org>
Sun, 5 May 2013 19:18:20 +0000 (22:18 +0300)
committerDavid Bremner <bremner@debian.org>
Sun, 12 May 2013 10:46:44 +0000 (07:46 -0300)
The use of realpath(3) in
commit 58ed67992d0ec1fa505026105218fa449f7980b0
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).

notmuch-config.c
test/setup

index d9c2eb3fe65957917bef62bfab61dbe74da32a8a..befe9b5b5c8a45a084d7a3fd2738b5344fa4a7bb 100644 (file)
@@ -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)) {
index 8cc557677d5d9e5cc36ac6691f367ef2a91d64ba..124ef1c8e04b94959453b0630d7f9e320e1c1507 100755 (executable)
@@ -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