Re: [PATCH v2 5/5] compact: provide user more information on after-compaction failures
[notmuch-archives.git] / 20 / 44071cbad4a56f45f76baccda96aebb2fb4e29
1 Return-Path: <adrien@bustany.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 99B1E431FBD\r
6         for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 14:52:38 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 klkh5PQPuAvZ for <notmuch@notmuchmail.org>;\r
16         Wed, 17 Oct 2012 14:52:38 -0700 (PDT)\r
17 Received: from mail.bustany.org (bustany.org [176.31.244.208])\r
18         by olra.theworths.org (Postfix) with ESMTP id 29137431FB6\r
19         for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 14:52:38 -0700 (PDT)\r
20 Received: from localhost.localdomain (91-158-5-86.elisa-laajakaista.fi\r
21         [91.158.5.86])\r
22         by mail.bustany.org (Postfix) with ESMTPSA id 736F5140209\r
23         for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 23:56:25 +0200 (CEST)\r
24 From: Adrien Bustany <adrien@bustany.org>\r
25 To: notmuch@notmuchmail.org\r
26 Subject: [PATCH 1/2] Add notmuch_database_flush method\r
27 Date: Thu, 18 Oct 2012 00:52:21 +0300\r
28 Message-Id: <1350510742-13447-2-git-send-email-adrien@bustany.org>\r
29 X-Mailer: git-send-email 1.7.11.7\r
30 In-Reply-To: <1350510742-13447-1-git-send-email-adrien@bustany.org>\r
31 References: <1342723401-26103-1-git-send-email-adrien@bustany.org>\r
32         <1350510742-13447-1-git-send-email-adrien@bustany.org>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.13\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37         <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Wed, 17 Oct 2012 21:52:38 -0000\r
46 \r
47 This method explicitly flushes the pending modifications to disk. It is\r
48 useful if your program has various threads, each with a read only DB and\r
49 one writer thread with a read/write DB. In that case, you most likely\r
50 want the writer to sync the changes to disk so that the readers can see\r
51 them, without having to close and reopen the database completely.\r
52 ---\r
53  lib/database.cc | 18 ++++++++++++++++++\r
54  lib/notmuch.h   |  4 ++++\r
55  2 files changed, 22 insertions(+)\r
56 \r
57 diff --git a/lib/database.cc b/lib/database.cc\r
58 index 761dc1a..1b680ab 100644\r
59 --- a/lib/database.cc\r
60 +++ b/lib/database.cc\r
61 @@ -745,6 +745,24 @@ notmuch_database_open (const char *path,\r
62      return status;\r
63  }\r
64  \r
65 +notmuch_status_t\r
66 +notmuch_database_flush(notmuch_database_t *notmuch)\r
67 +{\r
68 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
69 +\r
70 +    try {\r
71 +       if (notmuch->xapian_db != NULL &&\r
72 +           notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
73 +           (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
74 +    } catch (const Xapian::Error &error) {\r
75 +       fprintf(stderr, "A Xapian exception occured flushing the database: %s\n",\r
76 +               error.get_msg().c_str());\r
77 +       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
78 +    }\r
79 +\r
80 +    return status;\r
81 +}\r
82 +\r
83  void\r
84  notmuch_database_close (notmuch_database_t *notmuch)\r
85  {\r
86 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
87 index 3633bed..aef5c56 100644\r
88 --- a/lib/notmuch.h\r
89 +++ b/lib/notmuch.h\r
90 @@ -201,6 +201,10 @@ notmuch_database_open (const char *path,\r
91                        notmuch_database_mode_t mode,\r
92                        notmuch_database_t **database);\r
93  \r
94 +/* Flushes all the pending modifications to the database to disk. */\r
95 +notmuch_status_t\r
96 +notmuch_database_flush (notmuch_database_t *database);\r
97 +\r
98  /* Close the given notmuch database.\r
99   *\r
100   * After notmuch_database_close has been called, calls to other\r
101 -- \r
102 1.7.11.7\r
103 \r