From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH] config: do not overwrite symlinks when saving config file
Date: Sat, 2 Mar 2013 23:24:02 +0200 [thread overview]
Message-ID: <1362259442-21014-1-git-send-email-jani@nikula.org> (raw)
Use realpath on the config path before writing. If that fails,
fallback to the previous behaviour.
Previously 'notmuch setup' and 'notmuch config set' overwrote the
config file even if it was a symbolic link.
---
notmuch-config.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index b5c2066..1e7389f 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -461,7 +461,7 @@ int
notmuch_config_save (notmuch_config_t *config)
{
size_t length;
- char *data;
+ char *data, *filename;
GError *error = NULL;
data = g_key_file_to_data (config->key_file, &length, NULL);
@@ -470,14 +470,20 @@ notmuch_config_save (notmuch_config_t *config)
return 1;
}
- if (! g_file_set_contents (config->filename, data, length, &error)) {
+ /* Try not to overwrite symlinks. */
+ filename = realpath (config->filename, NULL);
+
+ if (! g_file_set_contents (filename ? filename : config->filename,
+ data, length, &error)) {
fprintf (stderr, "Error saving configuration to %s: %s\n",
config->filename, error->message);
g_error_free (error);
+ free (filename);
g_free (data);
return 1;
}
+ free (filename);
g_free (data);
return 0;
}
--
1.7.10.4
next reply other threads:[~2013-03-02 21:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-02 21:24 Jani Nikula [this message]
2013-03-02 21:58 ` [PATCH] config: do not overwrite symlinks when saving config file Tomi Ollila
2013-03-03 9:32 ` [PATCH v2] " Jani Nikula
2013-03-03 14:18 ` [PATCH v3] " Jani Nikula
2013-03-03 18:38 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1362259442-21014-1-git-send-email-jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).