[Patch v5 8/8] lib: eliminate fprintf from _notmuch_message_file_open
authorDavid Bremner <david@tethera.net>
Tue, 24 Mar 2015 13:24:11 +0000 (09:24 +2000)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:48:35 +0000 (14:48 -0700)
ad/65f566b503e8b058560aad6716f4024c99c38b [new file with mode: 0644]

diff --git a/ad/65f566b503e8b058560aad6716f4024c99c38b b/ad/65f566b503e8b058560aad6716f4024c99c38b
new file mode 100644 (file)
index 0000000..ba1812b
--- /dev/null
@@ -0,0 +1,146 @@
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 6EAEC429E42\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:26:39 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+       tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=unavailable\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 Uf-0fAYXkO3n for <notmuch@notmuchmail.org>;\r
+       Tue, 24 Mar 2015 06:26:39 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+       [87.98.215.224])\r
+       (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 68742429E2F\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:26:33 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+       4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+       id 1YaOq8-0000t6-9b; Tue, 24 Mar 2015 13:25:52 +0000\r
+Received: (nullmailer pid 2690 invoked by uid 1000); Tue, 24 Mar 2015\r
+       13:24:25 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: [Patch v5 8/8] lib: eliminate fprintf from _notmuch_message_file_open\r
+Date: Tue, 24 Mar 2015 09:24:11 -0400\r
+Message-Id: <1427203451-1540-9-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1427203451-1540-1-git-send-email-david@tethera.net>\r
+References: <1426352554-4383-10-git-send-email-david@tethera.net>\r
+       <1427203451-1540-1-git-send-email-david@tethera.net>\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: Tue, 24 Mar 2015 13:26:40 -0000\r
+\r
+You may wonder why _notmuch_message_file_open_ctx has two parameters.\r
+This is because we need sometime to use a ctx which is a\r
+notmuch_message_t. While we could get the database from this, there is\r
+no easy way in C to tell type we are getting.\r
+---\r
+ lib/database.cc       |  2 +-\r
+ lib/message-file.c    | 11 +++++++----\r
+ lib/message.cc        |  3 ++-\r
+ lib/notmuch-private.h |  5 +++--\r
+ 4 files changed, 13 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 155b5aa..85054df 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -2292,7 +2292,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+     if (ret)\r
+       return ret;\r
\r
+-    message_file = _notmuch_message_file_open (filename);\r
++    message_file = _notmuch_message_file_open (notmuch, filename);\r
+     if (message_file == NULL)\r
+       return NOTMUCH_STATUS_FILE_ERROR;\r
\r
+diff --git a/lib/message-file.c b/lib/message-file.c\r
+index a41d9ad..8ac96e8 100644\r
+--- a/lib/message-file.c\r
++++ b/lib/message-file.c\r
+@@ -76,7 +76,8 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)\r
+ /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as\r
+  * the talloc owner. */\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open_ctx (void *ctx, const char *filename)\r
++_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,\r
++                              void *ctx, const char *filename)\r
+ {\r
+     notmuch_message_file_t *message;\r
\r
+@@ -98,16 +99,18 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)\r
+     return message;\r
\r
+   FAIL:\r
+-    fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));\r
++    _notmuch_database_log (notmuch, "Error opening %s: %s\n",\r
++                        filename, strerror (errno));\r
+     _notmuch_message_file_close (message);\r
\r
+     return NULL;\r
+ }\r
\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open (const char *filename)\r
++_notmuch_message_file_open (notmuch_database_t *notmuch,\r
++                          const char *filename)\r
+ {\r
+-    return _notmuch_message_file_open_ctx (NULL, filename);\r
++    return _notmuch_message_file_open_ctx (notmuch, NULL, filename);\r
+ }\r
\r
+ void\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index a8ca988..5bc7aff 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -437,7 +437,8 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)\r
+     if (unlikely (filename == NULL))\r
+       return;\r
\r
+-    message->message_file = _notmuch_message_file_open_ctx (message, filename);\r
++    message->message_file = _notmuch_message_file_open_ctx (\r
++      _notmuch_message_database (message), message, filename);\r
+ }\r
\r
+ const char *\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index dc58a2f..cc9ce12 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -358,11 +358,12 @@ typedef struct _notmuch_message_file notmuch_message_file_t;\r
+  * Returns NULL if any error occurs.\r
+  */\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open (const char *filename);\r
++_notmuch_message_file_open (notmuch_database_t *notmuch, const char *filename);\r
\r
+ /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */\r
+ notmuch_message_file_t *\r
+-_notmuch_message_file_open_ctx (void *ctx, const char *filename);\r
++_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,\r
++                              void *ctx, const char *filename);\r
\r
+ /* Close a notmuch message previously opened with notmuch_message_open. */\r
+ void\r
+-- \r
+2.1.4\r
+\r