aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-config.c
diff options
context:
space:
mode:
authorGravatar Jani Nikula <jani@nikula.org>2013-05-05 22:18:20 +0300
committerGravatar David Bremner <bremner@debian.org>2013-05-12 07:46:44 -0300
commit9641fe1ce70d804ab4a9f63671e3905944dba7e5 (patch)
treedeb66a2da53ac49a3f688e39461ea6285b62373f /notmuch-config.c
parent2c64c2e0eb5bbf723313eef8913085dae0df4305 (diff)
cli: config: fix config file save when the file does not exist
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).
Diffstat (limited to 'notmuch-config.c')
-rw-r--r--notmuch-config.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index d9c2eb3f..befe9b5b 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)) {