Re: Avoiding the "huge INBOX of death"
[notmuch-archives.git] / 4b / ea560ed5e3ca93548fa9e890a286cd608c198c
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 2E47C431FAF\r
6         for <notmuch@notmuchmail.org>; Sun,  3 Mar 2013 06:18:36 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 WvNfCAKmOkhO for <notmuch@notmuchmail.org>;\r
16         Sun,  3 Mar 2013 06:18:35 -0800 (PST)\r
17 Received: from mail-la0-f46.google.com (mail-la0-f46.google.com\r
18         [209.85.215.46]) (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 7FA6F431FAE\r
21         for <notmuch@notmuchmail.org>; Sun,  3 Mar 2013 06:18:35 -0800 (PST)\r
22 Received: by mail-la0-f46.google.com with SMTP id fq12so4158221lab.5\r
23         for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 06:18:32 -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=nvE8ta7V/iP2jnsQO+ImB6cAYABZeSb4fxsVxp3FQgE=;\r
29         b=XZXIfzQq0l2B2qkBZf5kr+fLUckiJQPq1MVaWc6n5iY3e+T8qB/rukIJZXPxtkdciZ\r
30         c+eZe6svJgM3h6pNqW9c201B7lStCvpY1JVW/KDAPooHeqRYfzwhNC6eOTYn2mE/rWPM\r
31         RQj/oKQDi9hlKBdc7xrH6gV5a+KwymfhJ+tyx0FBzXZjpxb9x2AF5oD/54qGp28fVs6j\r
32         vyhzqrR7NmPryvPNZtMC0OWUQ6P5ucPYjOL4S2wW/c/ljUuRNCVmHoKzCmVgxA1lBZHT\r
33         XmO/1cY44tK3kBpiA71r8TFRZFoNRnbNMKijVDEhpvOLy4G64Wrz6XRQpBSUv0rcbUoo\r
34         pW2g==\r
35 X-Received: by 10.152.144.202 with SMTP id so10mr15105316lab.9.1362320312590; \r
36         Sun, 03 Mar 2013 06:18:32 -0800 (PST)\r
37 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
38         [80.223.81.27])\r
39         by mx.google.com with ESMTPS id e11sm6239987lbd.11.2013.03.03.06.18.30\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sun, 03 Mar 2013 06:18:31 -0800 (PST)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v3] config: do not overwrite symlinks when saving config file\r
45 Date: Sun,  3 Mar 2013 16:18:30 +0200\r
46 Message-Id: <1362320310-10930-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
50 X-Gm-Message-State:\r
51  ALoCoQmFQkaZjEVYT5sxtPw1G+ssEArBrDgMjG+Vs6m1GRjhAH/sWBVV3LlaGUVu7TJ1jLemPcq0\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
55 Precedence: list\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 14:18:36 -0000\r
66 \r
67 Use realpath to canonicalize the config path before writing.\r
68 \r
69 Previously 'notmuch setup' and 'notmuch config set' overwrote the\r
70 config file even if it was a symbolic link.\r
71 \r
72 ---\r
73 \r
74 v3: compared to v2, as suggested by Tomi on IRC:\r
75 \r
76 -       if (strcmp (filename, config->filename)) {\r
77 +       if (strcmp (filename, config->filename) != 0) {\r
78 ---\r
79  notmuch-config.c |   24 ++++++++++++++++++++----\r
80  1 file changed, 20 insertions(+), 4 deletions(-)\r
81 \r
82 diff --git a/notmuch-config.c b/notmuch-config.c\r
83 index b5c2066..8adb404 100644\r
84 --- a/notmuch-config.c\r
85 +++ b/notmuch-config.c\r
86 @@ -461,7 +461,7 @@ int\r
87  notmuch_config_save (notmuch_config_t *config)\r
88  {\r
89      size_t length;\r
90 -    char *data;\r
91 +    char *data, *filename;\r
92      GError *error = NULL;\r
93  \r
94      data = g_key_file_to_data (config->key_file, &length, NULL);\r
95 @@ -470,14 +470,30 @@ notmuch_config_save (notmuch_config_t *config)\r
96         return 1;\r
97      }\r
98  \r
99 -    if (! g_file_set_contents (config->filename, data, length, &error)) {\r
100 -       fprintf (stderr, "Error saving configuration to %s: %s\n",\r
101 -                config->filename, error->message);\r
102 +    /* Try not to overwrite symlinks. */\r
103 +    filename = realpath (config->filename, NULL);\r
104 +    if (! filename) {\r
105 +       fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,\r
106 +                strerror (errno));\r
107 +       g_free (data);\r
108 +       return 1;\r
109 +    }\r
110 +\r
111 +    if (! g_file_set_contents (filename, data, length, &error)) {\r
112 +       if (strcmp (filename, config->filename) != 0) {\r
113 +           fprintf (stderr, "Error saving configuration to %s (-> %s): %s\n",\r
114 +                    config->filename, filename, error->message);\r
115 +       } else {\r
116 +           fprintf (stderr, "Error saving configuration to %s: %s\n",\r
117 +                    filename, error->message);\r
118 +       }\r
119         g_error_free (error);\r
120 +       free (filename);\r
121         g_free (data);\r
122         return 1;\r
123      }\r
124  \r
125 +    free (filename);\r
126      g_free (data);\r
127      return 0;\r
128  }\r
129 -- \r
130 1.7.10.4\r
131 \r