* [PATCH 2/2] cli: config: fix config file save when the file does not exist
2013-05-05 19:18 [PATCH 1/2] test: add basic test for notmuch setup Jani Nikula
@ 2013-05-05 19:18 ` Jani Nikula
2013-05-05 19:27 ` [PATCH 1/2] test: add basic test for notmuch setup Tomi Ollila
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2013-05-05 19:18 UTC (permalink / raw)
To: notmuch; +Cc: Tomi Ollila
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 | 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@example.com
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] test: add basic test for notmuch setup
2013-05-05 19:18 [PATCH 1/2] test: add basic test for notmuch setup Jani Nikula
2013-05-05 19:18 ` [PATCH 2/2] cli: config: fix config file save when the file does not exist Jani Nikula
@ 2013-05-05 19:27 ` Tomi Ollila
2013-05-11 21:47 ` Mark Walters
2013-05-12 10:58 ` David Bremner
3 siblings, 0 replies; 5+ messages in thread
From: Tomi Ollila @ 2013-05-05 19:27 UTC (permalink / raw)
To: notmuch
On Sun, May 05 2013, Jani Nikula <jani@nikula.org> wrote:
> And annotate with test_subtest_known_broken. Hooray.
> ---
LGTM (both patches). Tests pass (both make test and hand-tested
setup without having file ~/.notmuch-config).
Tomi
> test/notmuch-test | 1 +
> test/setup | 28 ++++++++++++++++++++++++++++
> 2 files changed, 29 insertions(+)
> create mode 100755 test/setup
>
> diff --git a/test/notmuch-test b/test/notmuch-test
> index ca9c3dc..27a144e 100755
> --- a/test/notmuch-test
> +++ b/test/notmuch-test
> @@ -20,6 +20,7 @@ TESTS="
> basic
> help-test
> config
> + setup
> new
> count
> search
> diff --git a/test/setup b/test/setup
> new file mode 100755
> index 0000000..8cc5576
> --- /dev/null
> +++ b/test/setup
> @@ -0,0 +1,28 @@
> +#!/usr/bin/env bash
> +
> +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
> +another.suite@example.com
> +
> +/path/to/maildir
> +foo bar
> +baz
> +EOF
> +output=$(notmuch --config=new-notmuch-config config list)
> +test_expect_equal "$output" "\
> +database.path=/path/to/maildir
> +user.name=Test Suite
> +user.primary_email=test.suite@example.com
> +user.other_email=another.suite@example.com;
> +new.tags=foo;bar;
> +new.ignore=
> +search.exclude_tags=baz;
> +maildir.synchronize_flags=true"
> +
> +test_done
> --
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] test: add basic test for notmuch setup
2013-05-05 19:18 [PATCH 1/2] test: add basic test for notmuch setup Jani Nikula
2013-05-05 19:18 ` [PATCH 2/2] cli: config: fix config file save when the file does not exist Jani Nikula
2013-05-05 19:27 ` [PATCH 1/2] test: add basic test for notmuch setup Tomi Ollila
@ 2013-05-11 21:47 ` Mark Walters
2013-05-12 10:58 ` David Bremner
3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2013-05-11 21:47 UTC (permalink / raw)
To: Jani Nikula, notmuch; +Cc: Tomi Ollila
Hi
These patches look good to me.
Best wishes
Mark
On Sun, 05 May 2013, Jani Nikula <jani@nikula.org> wrote:
> And annotate with test_subtest_known_broken. Hooray.
> ---
> test/notmuch-test | 1 +
> test/setup | 28 ++++++++++++++++++++++++++++
> 2 files changed, 29 insertions(+)
> create mode 100755 test/setup
>
> diff --git a/test/notmuch-test b/test/notmuch-test
> index ca9c3dc..27a144e 100755
> --- a/test/notmuch-test
> +++ b/test/notmuch-test
> @@ -20,6 +20,7 @@ TESTS="
> basic
> help-test
> config
> + setup
> new
> count
> search
> diff --git a/test/setup b/test/setup
> new file mode 100755
> index 0000000..8cc5576
> --- /dev/null
> +++ b/test/setup
> @@ -0,0 +1,28 @@
> +#!/usr/bin/env bash
> +
> +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
> +another.suite@example.com
> +
> +/path/to/maildir
> +foo bar
> +baz
> +EOF
> +output=$(notmuch --config=new-notmuch-config config list)
> +test_expect_equal "$output" "\
> +database.path=/path/to/maildir
> +user.name=Test Suite
> +user.primary_email=test.suite@example.com
> +user.other_email=another.suite@example.com;
> +new.tags=foo;bar;
> +new.ignore=
> +search.exclude_tags=baz;
> +maildir.synchronize_flags=true"
> +
> +test_done
> --
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] test: add basic test for notmuch setup
2013-05-05 19:18 [PATCH 1/2] test: add basic test for notmuch setup Jani Nikula
` (2 preceding siblings ...)
2013-05-11 21:47 ` Mark Walters
@ 2013-05-12 10:58 ` David Bremner
3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2013-05-12 10:58 UTC (permalink / raw)
To: Jani Nikula, notmuch; +Cc: Tomi Ollila
Jani Nikula <jani@nikula.org> writes:
> And annotate with test_subtest_known_broken. Hooray.
Pushed these two.
d
^ permalink raw reply [flat|nested] 5+ messages in thread