1 Return-Path: <tomi.ollila@iki.fi>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id D9E74431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 10:39:06 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 2wtAZ8CICSdO for <notmuch@notmuchmail.org>;
\r
16 Sun, 3 Mar 2013 10:39:05 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 5E954431FAE
\r
19 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 10:39:05 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id 38407100051;
\r
22 Sun, 3 Mar 2013 20:38:53 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH v3] config: do not overwrite symlinks when saving config
\r
27 In-Reply-To: <1362320310-10930-1-git-send-email-jani@nikula.org>
\r
28 References: <m2mwultqff.fsf@guru.guru-group.fi>
\r
29 <1362320310-10930-1-git-send-email-jani@nikula.org>
\r
30 User-Agent: Notmuch/0.15.2+48~g8dcc33e (http://notmuchmail.org) Emacs/24.2.1
\r
31 (x86_64-unknown-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Sun, 03 Mar 2013 20:38:52 +0200
\r
36 Message-ID: <m2ehfwtjk3.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Sun, 03 Mar 2013 18:39:07 -0000
\r
53 On Sun, Mar 03 2013, Jani Nikula <jani@nikula.org> wrote:
\r
55 > Use realpath to canonicalize the config path before writing.
\r
57 > Previously 'notmuch setup' and 'notmuch config set' overwrote the
\r
58 > config file even if it was a symbolic link.
\r
62 > v3: compared to v2, as suggested by Tomi on IRC:
\r
64 > - if (strcmp (filename, config->filename)) {
\r
65 > + if (strcmp (filename, config->filename) != 0) {
\r
73 > notmuch-config.c | 24 ++++++++++++++++++++----
\r
74 > 1 file changed, 20 insertions(+), 4 deletions(-)
\r
76 > diff --git a/notmuch-config.c b/notmuch-config.c
\r
77 > index b5c2066..8adb404 100644
\r
78 > --- a/notmuch-config.c
\r
79 > +++ b/notmuch-config.c
\r
80 > @@ -461,7 +461,7 @@ int
\r
81 > notmuch_config_save (notmuch_config_t *config)
\r
85 > + char *data, *filename;
\r
86 > GError *error = NULL;
\r
88 > data = g_key_file_to_data (config->key_file, &length, NULL);
\r
89 > @@ -470,14 +470,30 @@ notmuch_config_save (notmuch_config_t *config)
\r
93 > - if (! g_file_set_contents (config->filename, data, length, &error)) {
\r
94 > - fprintf (stderr, "Error saving configuration to %s: %s\n",
\r
95 > - config->filename, error->message);
\r
96 > + /* Try not to overwrite symlinks. */
\r
97 > + filename = realpath (config->filename, NULL);
\r
98 > + if (! filename) {
\r
99 > + fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,
\r
100 > + strerror (errno));
\r
105 > + if (! g_file_set_contents (filename, data, length, &error)) {
\r
106 > + if (strcmp (filename, config->filename) != 0) {
\r
107 > + fprintf (stderr, "Error saving configuration to %s (-> %s): %s\n",
\r
108 > + config->filename, filename, error->message);
\r
110 > + fprintf (stderr, "Error saving configuration to %s: %s\n",
\r
111 > + filename, error->message);
\r
113 > g_error_free (error);
\r
114 > + free (filename);
\r
119 > + free (filename);
\r
126 > _______________________________________________
\r
127 > notmuch mailing list
\r
128 > notmuch@notmuchmail.org
\r
129 > http://notmuchmail.org/mailman/listinfo/notmuch
\r