1 Return-Path: <jani@nikula.org>
\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 4360A431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 01:32:45 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\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 iZjLYD11ZVP3 for <notmuch@notmuchmail.org>;
\r
16 Sun, 3 Mar 2013 01:32:44 -0800 (PST)
\r
17 Received: from mail-la0-f51.google.com (mail-la0-f51.google.com
\r
18 [209.85.215.51]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 87174431FAE
\r
21 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 01:32:44 -0800 (PST)
\r
22 Received: by mail-la0-f51.google.com with SMTP id fo13so4049532lab.24
\r
23 for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 01:32:42 -0800 (PST)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
27 :references:x-gm-message-state;
\r
28 bh=O4pjaPTphCdGks3y1eAP+6VJy3Rqk+UeD0jM57SOYp4=;
\r
29 b=CduZ2S+99l1nyLuo7HG0I2DE/BcpLQnDBeHpaqrQTYaan/yctpEWB1n1lbfHH6lDW4
\r
30 5S9nHJ9QbhP8itd96jH94XrzNWAjIWOrU5CG4j7JlQ8qWlZKPs3+J98jD3hX0HmjUm+S
\r
31 /4K9D4Z814weoKWqx/oXVplYAS6CaDCnbpct4MUeeUfFtXREiFWnQRCX5I6pR56EMn6s
\r
32 NAJRokQ+8uI3Lcc9QWQGr5J9kqHs0UCBqapU5OmVgEB7xFT6KSg0GIhelyJ0qfyZHneF
\r
33 9IGRG/tHyGBt5W1g4b1Rp4JhUVRYBw9S/8ZMi7GiY5xDpaOQqrNt4wKU5185zwAzmXnV
\r
35 X-Received: by 10.112.8.231 with SMTP id u7mr2914562lba.45.1362303161462;
\r
36 Sun, 03 Mar 2013 01:32:41 -0800 (PST)
\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
39 by mx.google.com with ESMTPS id t17sm9740402lam.9.2013.03.03.01.32.38
\r
40 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
41 Sun, 03 Mar 2013 01:32:40 -0800 (PST)
\r
42 From: Jani Nikula <jani@nikula.org>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH v2] config: do not overwrite symlinks when saving config file
\r
45 Date: Sun, 3 Mar 2013 11:32:32 +0200
\r
46 Message-Id: <1362303152-25793-1-git-send-email-jani@nikula.org>
\r
47 X-Mailer: git-send-email 1.7.10.4
\r
48 In-Reply-To: <m2mwultqff.fsf@guru.guru-group.fi>
\r
49 References: <m2mwultqff.fsf@guru.guru-group.fi>
\r
51 ALoCoQkkn+8iap9zIYBZW60LShZ1PbFBe4q4l6SP+oBSsRL9JHl9R81Oeu5btiiXLIHw7sglyYhO
\r
52 Cc: Tomi Ollila <tomi.ollila@iki.fi>
\r
53 X-BeenThere: notmuch@notmuchmail.org
\r
54 X-Mailman-Version: 2.1.13
\r
56 List-Id: "Use and development of the notmuch mail system."
\r
57 <notmuch.notmuchmail.org>
\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
61 List-Post: <mailto:notmuch@notmuchmail.org>
\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
65 X-List-Received-Date: Sun, 03 Mar 2013 09:32:45 -0000
\r
67 Use realpath to canonicalize the config path before writing.
\r
69 Previously 'notmuch setup' and 'notmuch config set' overwrote the
\r
70 config file even if it was a symbolic link.
\r
72 notmuch-config.c | 24 ++++++++++++++++++++----
\r
73 1 file changed, 20 insertions(+), 4 deletions(-)
\r
75 diff --git a/notmuch-config.c b/notmuch-config.c
\r
76 index b5c2066..89bc143 100644
\r
77 --- a/notmuch-config.c
\r
78 +++ b/notmuch-config.c
\r
79 @@ -461,7 +461,7 @@ int
\r
80 notmuch_config_save (notmuch_config_t *config)
\r
84 + char *data, *filename;
\r
85 GError *error = NULL;
\r
87 data = g_key_file_to_data (config->key_file, &length, NULL);
\r
88 @@ -470,14 +470,30 @@ notmuch_config_save (notmuch_config_t *config)
\r
92 - if (! g_file_set_contents (config->filename, data, length, &error)) {
\r
93 - fprintf (stderr, "Error saving configuration to %s: %s\n",
\r
94 - config->filename, error->message);
\r
95 + /* Try not to overwrite symlinks. */
\r
96 + filename = realpath (config->filename, NULL);
\r
98 + fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,
\r
99 + strerror (errno));
\r
104 + if (! g_file_set_contents (filename, data, length, &error)) {
\r
105 + if (strcmp (filename, config->filename)) {
\r
106 + fprintf (stderr, "Error saving configuration to %s (-> %s): %s\n",
\r
107 + config->filename, filename, error->message);
\r
109 + fprintf (stderr, "Error saving configuration to %s: %s\n",
\r
110 + filename, error->message);
\r
112 g_error_free (error);
\r