[PATCH 2/2] cli: config: fix config file save when the file does not exist
authorJani Nikula <jani@nikula.org>
Sun, 5 May 2013 19:18:20 +0000 (22:18 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:54:38 +0000 (09:54 -0800)
04/3fa5f0e5711987a8eae8ed396d6fa7f03735c8 [new file with mode: 0644]

diff --git a/04/3fa5f0e5711987a8eae8ed396d6fa7f03735c8 b/04/3fa5f0e5711987a8eae8ed396d6fa7f03735c8
new file mode 100644 (file)
index 0000000..de4e8f3
--- /dev/null
@@ -0,0 +1,135 @@
+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 52DF0431FC2\r
+       for <notmuch@notmuchmail.org>; Sun,  5 May 2013 12:18:36 -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 Ibbu4LDRCJBp for <notmuch@notmuchmail.org>;\r
+       Sun,  5 May 2013 12:18:31 -0700 (PDT)\r
+Received: from mail-la0-f54.google.com (mail-la0-f54.google.com\r
+       [209.85.215.54]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 77338431FAF\r
+       for <notmuch@notmuchmail.org>; Sun,  5 May 2013 12:18:31 -0700 (PDT)\r
+Received: by mail-la0-f54.google.com with SMTP id fd20so2792525lab.13\r
+       for <notmuch@notmuchmail.org>; Sun, 05 May 2013 12:18:29 -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=5tNUn1jY6e6wO083LbMGb5kYv1FhDGZ2zIA44fcygpA=;\r
+       b=mMX4bpu0cEz9JIC/7w5VBN6PBmbQvaU1GQcVq/FTuXQLxPFSKyNNEPuKoopJubRvzA\r
+       1BgN3GWHKPpf9fvbXCnOo4iOF0tGTdQ24DrfMh9mLMINOGSpuPOA+4ubKRKgBKdw4PyA\r
+       GWjLtvURnyjpVoWCjRpPGrHlyfyx4wN+Mkn9j+qeUdxITFGgFMIBtSqgECAcpuSNT4TD\r
+       LS8QXiK8lVEpzLwlUeq3lc5KJ3BQ+ygtOSSZzj/u2iZbzctB6IRLVZ8ppvtRbsVnRCRW\r
+       7VA2gUZxtzTx5/xP0t6w/rmwWLlDcTiRxFY7iO07I+6hOX7Yqy9ECz4D9qbyo7+/8XD0\r
+       XWsw==\r
+X-Received: by 10.152.2.196 with SMTP id 4mr7039340law.4.1367781509834;\r
+       Sun, 05 May 2013 12:18:29 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c376-211.dhcp.inet.fi.\r
+       [88.195.118.211])\r
+       by mx.google.com with ESMTPSA id 2sm3837120lay.5.2013.05.05.12.18.28\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 05 May 2013 12:18:29 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] cli: config: fix config file save when the file does not\r
+       exist\r
+Date: Sun,  5 May 2013 22:18:20 +0300\r
+Message-Id:\r
+ <66bdb2255d3a5ec573ac2a935663e9f767610d36.1367781422.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To:\r
+ <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org>\r
+References:\r
+ <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org>\r
+In-Reply-To:\r
+ <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org>\r
+References:\r
+ <9971e27c7c3fe569765bbca0f21de128ad1e4fac.1367781422.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQlYtu6/ccs0Sugw4PsV4PR99KP1soIemcIR6n4k/jof+3bQpuEISQYnEo8l7tEGvySBxvG3\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, 05 May 2013 19:18:36 -0000\r
+\r
+The use of realpath(3) in\r
+commit 58ed67992d0ec1fa505026105218fa449f7980b0\r
+Author: Jani Nikula <jani@nikula.org>\r
+Date:   Sun Apr 7 20:15:03 2013 +0300\r
+\r
+    cli: config: do not overwrite symlinks when saving config file\r
+\r
+broke config file save when the file does not exist, which results in\r
+'notmuch setup' always failing to create a new config file.\r
+\r
+Fix by checking ENOENT from realpath(3).\r
+---\r
+ notmuch-config.c |   17 +++++++++++++----\r
+ test/setup       |    1 -\r
+ 2 files changed, 13 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index d9c2eb3..befe9b5 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -456,10 +456,19 @@ notmuch_config_save (notmuch_config_t *config)\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
++      if (errno == ENOENT) {\r
++          filename = strdup (config->filename);\r
++          if (! filename) {\r
++              fprintf (stderr, "Out of memory.\n");\r
++              g_free (data);\r
++              return 1;\r
++          }\r
++      } else {\r
++          fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename,\r
++                   strerror (errno));\r
++          g_free (data);\r
++          return 1;\r
++      }\r
+     }\r
\r
+     if (! g_file_set_contents (filename, data, length, &error)) {\r
+diff --git a/test/setup b/test/setup\r
+index 8cc5576..124ef1c 100755\r
+--- a/test/setup\r
++++ b/test/setup\r
+@@ -4,7 +4,6 @@ test_description='"notmuch setup"'\r
+ . ./test-lib.sh\r
\r
+ test_begin_subtest "Create a new config interactively"\r
+-test_subtest_known_broken\r
+ notmuch --config=new-notmuch-config > /dev/null <<EOF\r
+ Test Suite\r
+ test.suite@example.com\r
+-- \r
+1.7.10.4\r
+\r