--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id CC4B1431FD5\r
+ for <notmuch@notmuchmail.org>; Sun, 7 Apr 2013 10:15:21 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id LM63a-k5T2xq for <notmuch@notmuchmail.org>;\r
+ Sun, 7 Apr 2013 10:15:20 -0700 (PDT)\r
+Received: from mail-la0-f41.google.com (mail-la0-f41.google.com\r
+ [209.85.215.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 30E34431FCB\r
+ for <notmuch@notmuchmail.org>; Sun, 7 Apr 2013 10:15:20 -0700 (PDT)\r
+Received: by mail-la0-f41.google.com with SMTP id eg20so665140lab.28\r
+ for <notmuch@notmuchmail.org>; Sun, 07 Apr 2013 10:15:17 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+ :references:in-reply-to:references:x-gm-message-state;\r
+ bh=7DB9c1D52BfgAp/3fsKGTtVlx0hpWx7idOBaEE9dhRQ=;\r
+ b=DcXnJmTL1nIFQ3+Tr5myVBxKMgLqhOBTq5GMOBilCBBOwxDLaHnqGKQOO0/Pjzcg+I\r
+ dfeQONhmBrBGUCdrq2BnfohQzUNWcA6CmZzO6Mm34VZeabZ55gJa60HO+Bbje86aUbyx\r
+ FgDbgyPbgRlF7WAw0qCpeQlDzX6uv1T8LIM36smRhe/y7Whyimh0iIPsTM6v96fHF7bT\r
+ 8RcQUkGMTyItoirOjaqLiaQcK8Xzg8FlGEoQyQY2a+zsPgGQTSxicyiYb+LZqu9pYICT\r
+ O0SEkG6rOODDQcRbYQzd+BnYLOBb9WCCBYDirLBWtL1tKrP2ImpZmJYfw7GhZNTLs9O+\r
+ QZfg==\r
+X-Received: by 10.112.154.170 with SMTP id vp10mr5937697lbb.10.1365354917336; \r
+ Sun, 07 Apr 2013 10:15:17 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+ [80.223.81.27])\r
+ by mx.google.com with ESMTPS id c7sm9250623lbe.6.2013.04.07.10.15.15\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 07 Apr 2013 10:15:16 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] cli: config: do not overwrite symlinks when saving config\r
+ file\r
+Date: Sun, 7 Apr 2013 20:15:03 +0300\r
+Message-Id:\r
+ <5502b2718a124b074b14c1835320e8b825a79045.1365354320.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1365354320.git.jani@nikula.org>\r
+References: <cover.1365354320.git.jani@nikula.org>\r
+In-Reply-To: <cover.1365354320.git.jani@nikula.org>\r
+References: <cover.1365354320.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQmyo412e5C/Ju0/PFulYZ6RYWpN/rYa4fL7F9BIa3WAPey42sIADzWIRe0LsDpai4m/5asT\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 07 Apr 2013 17:15:22 -0000\r
+\r
+Use realpath to canonicalize the config path before writing.\r
+\r
+Previously 'notmuch setup' and 'notmuch config set' overwrote the\r
+config file even if it was a symbolic link.\r
+---\r
+ notmuch-config.c | 24 ++++++++++++++++++++----\r
+ test/config | 1 -\r
+ 2 files changed, 20 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 66a1cdf..d9c2eb3 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -444,7 +444,7 @@ int\r
+ notmuch_config_save (notmuch_config_t *config)\r
+ {\r
+ size_t length;\r
+- char *data;\r
++ char *data, *filename;\r
+ GError *error = NULL;\r
+ \r
+ data = g_key_file_to_data (config->key_file, &length, NULL);\r
+@@ -453,14 +453,30 @@ notmuch_config_save (notmuch_config_t *config)\r
+ return 1;\r
+ }\r
+ \r
+- if (! g_file_set_contents (config->filename, data, length, &error)) {\r
+- fprintf (stderr, "Error saving configuration to %s: %s\n",\r
+- config->filename, error->message);\r
++ /* Try not to overwrite symlinks. */\r
++ filename = realpath (config->filename, NULL);\r
++ if (! filename) {\r
++ fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,\r
++ strerror (errno));\r
++ g_free (data);\r
++ return 1;\r
++ }\r
++\r
++ if (! g_file_set_contents (filename, data, length, &error)) {\r
++ if (strcmp (filename, config->filename) != 0) {\r
++ fprintf (stderr, "Error saving configuration to %s (-> %s): %s\n",\r
++ config->filename, filename, error->message);\r
++ } else {\r
++ fprintf (stderr, "Error saving configuration to %s: %s\n",\r
++ filename, error->message);\r
++ }\r
+ g_error_free (error);\r
++ free (filename);\r
+ g_free (data);\r
+ return 1;\r
+ }\r
+ \r
++ free (filename);\r
+ g_free (data);\r
+ return 0;\r
+ }\r
+diff --git a/test/config b/test/config\r
+index 344eced..ca4cf33 100755\r
+--- a/test/config\r
++++ b/test/config\r
+@@ -78,7 +78,6 @@ test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \\r
+ "Link Name"\r
+ \r
+ test_begin_subtest "Writing config file through symlink follows symlink"\r
+-test_subtest_known_broken\r
+ test_expect_equal "$(readlink alt-config-link)" "alt-config"\r
+ \r
+ test_done\r
+-- \r
+1.7.10.4\r
+\r