[PATCH 1/2] Add notmuch_database_flush method
authorAdrien Bustany <adrien@bustany.org>
Wed, 17 Oct 2012 21:52:21 +0000 (00:52 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:50 +0000 (09:49 -0800)
20/44071cbad4a56f45f76baccda96aebb2fb4e29 [new file with mode: 0644]

diff --git a/20/44071cbad4a56f45f76baccda96aebb2fb4e29 b/20/44071cbad4a56f45f76baccda96aebb2fb4e29
new file mode 100644 (file)
index 0000000..b616df1
--- /dev/null
@@ -0,0 +1,103 @@
+Return-Path: <adrien@bustany.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 99B1E431FBD\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 14:52:38 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 klkh5PQPuAvZ for <notmuch@notmuchmail.org>;\r
+       Wed, 17 Oct 2012 14:52:38 -0700 (PDT)\r
+Received: from mail.bustany.org (bustany.org [176.31.244.208])\r
+       by olra.theworths.org (Postfix) with ESMTP id 29137431FB6\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 14:52:38 -0700 (PDT)\r
+Received: from localhost.localdomain (91-158-5-86.elisa-laajakaista.fi\r
+       [91.158.5.86])\r
+       by mail.bustany.org (Postfix) with ESMTPSA id 736F5140209\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 23:56:25 +0200 (CEST)\r
+From: Adrien Bustany <adrien@bustany.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] Add notmuch_database_flush method\r
+Date: Thu, 18 Oct 2012 00:52:21 +0300\r
+Message-Id: <1350510742-13447-2-git-send-email-adrien@bustany.org>\r
+X-Mailer: git-send-email 1.7.11.7\r
+In-Reply-To: <1350510742-13447-1-git-send-email-adrien@bustany.org>\r
+References: <1342723401-26103-1-git-send-email-adrien@bustany.org>\r
+       <1350510742-13447-1-git-send-email-adrien@bustany.org>\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: Wed, 17 Oct 2012 21:52:38 -0000\r
+\r
+This method explicitly flushes the pending modifications to disk. It is\r
+useful if your program has various threads, each with a read only DB and\r
+one writer thread with a read/write DB. In that case, you most likely\r
+want the writer to sync the changes to disk so that the readers can see\r
+them, without having to close and reopen the database completely.\r
+---\r
+ lib/database.cc | 18 ++++++++++++++++++\r
+ lib/notmuch.h   |  4 ++++\r
+ 2 files changed, 22 insertions(+)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 761dc1a..1b680ab 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -745,6 +745,24 @@ notmuch_database_open (const char *path,\r
+     return status;\r
+ }\r
\r
++notmuch_status_t\r
++notmuch_database_flush(notmuch_database_t *notmuch)\r
++{\r
++    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
++\r
++    try {\r
++      if (notmuch->xapian_db != NULL &&\r
++          notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
++          (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
++    } catch (const Xapian::Error &error) {\r
++      fprintf(stderr, "A Xapian exception occured flushing the database: %s\n",\r
++              error.get_msg().c_str());\r
++      status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
++    }\r
++\r
++    return status;\r
++}\r
++\r
+ void\r
+ notmuch_database_close (notmuch_database_t *notmuch)\r
+ {\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 3633bed..aef5c56 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -201,6 +201,10 @@ notmuch_database_open (const char *path,\r
+                      notmuch_database_mode_t mode,\r
+                      notmuch_database_t **database);\r
\r
++/* Flushes all the pending modifications to the database to disk. */\r
++notmuch_status_t\r
++notmuch_database_flush (notmuch_database_t *database);\r
++\r
+ /* Close the given notmuch database.\r
+  *\r
+  * After notmuch_database_close has been called, calls to other\r
+-- \r
+1.7.11.7\r
+\r