database error
[notmuch-archives.git] / eb / 2d0a4029ce3cec711c67c988f9d3ff9abd71e4
1 Return-Path: <bremner@unb.ca>\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 440D140D148\r
6         for <notmuch@notmuchmail.org>; Sun, 24 Oct 2010 14:01:39 -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: -2.6\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham\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 N6nvxMX8CEYi for <notmuch@notmuchmail.org>;\r
16         Sun, 24 Oct 2010 14:01:25 -0700 (PDT)\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
18         by olra.theworths.org (Postfix) with ESMTP id A87D540D154\r
19         for <notmuch@notmuchmail.org>; Sun, 24 Oct 2010 14:01:14 -0700 (PDT)\r
20 Received: from rocinante.cs.unb.ca\r
21         (fctnnbsc30w-142167176217.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
22         [142.167.176.217]) (authenticated bits=0)\r
23         by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id o9OL1Bab017814\r
24         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
25         Sun, 24 Oct 2010 18:01:14 -0300\r
26 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.72)\r
27         (envelope-from <bremner@unb.ca>)\r
28         id 1PA7gl-0006Op-HB; Sun, 24 Oct 2010 18:01:11 -0300\r
29 From: david@tethera.net\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH 3/4] Add logging to low level message handling routines.\r
32 Date: Sun, 24 Oct 2010 18:01:05 -0300\r
33 Message-Id: <1287954066-24512-4-git-send-email-david@tethera.net>\r
34 X-Mailer: git-send-email 1.7.1\r
35 In-Reply-To: <1286803617-17328-1-git-send-email-david@tethera.net>\r
36 References: <1286803617-17328-1-git-send-email-david@tethera.net>\r
37 Cc: David Bremner <bremner@unb.ca>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sun, 24 Oct 2010 21:01:39 -0000\r
51 \r
52 From: David Bremner <bremner@unb.ca>\r
53 \r
54 This might not be ideal from the point of view of "atomic"\r
55 transactions, but it is transparent to the caller of the library.\r
56 ---\r
57  lib/message.cc |   30 ++++++++++++++++++++++++++++++\r
58  1 files changed, 30 insertions(+), 0 deletions(-)\r
59 \r
60 diff --git a/lib/message.cc b/lib/message.cc\r
61 index 71f5619..0385e68 100644\r
62 --- a/lib/message.cc\r
63 +++ b/lib/message.cc\r
64 @@ -600,12 +600,17 @@ void\r
65  _notmuch_message_sync (notmuch_message_t *message)\r
66  {\r
67      Xapian::WritableDatabase *db;\r
68 +    notmuch_log_t *log;\r
69  \r
70      if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
71         return;\r
72  \r
73      db = static_cast <Xapian::WritableDatabase *> (message->notmuch->xapian_db);\r
74      db->replace_document (message->doc_id, message->doc);\r
75 +\r
76 +    log = notmuch_database_get_log(message->notmuch);\r
77 +    if (log)\r
78 +       notmuch_log_sync (log);\r
79  }\r
80  \r
81  /* Ensure that 'message' is not holding any file object open. Future\r
82 @@ -635,10 +640,16 @@ _notmuch_message_add_term (notmuch_message_t *message,\r
83  {\r
84  \r
85      char *term;\r
86 +    notmuch_log_t *log;\r
87  \r
88      if (value == NULL)\r
89         return NOTMUCH_PRIVATE_STATUS_NULL_POINTER;\r
90  \r
91 +    log=notmuch_database_get_log(message->notmuch);\r
92 +    if (log)\r
93 +       notmuch_log_words (log,"+", prefix_name, value,\r
94 +                          notmuch_message_get_message_id (message), NULL);\r
95 +\r
96      term = talloc_asprintf (message, "%s%s",\r
97                             _find_prefix (prefix_name), value);\r
98  \r
99 @@ -691,10 +702,16 @@ _notmuch_message_remove_term (notmuch_message_t *message,\r
100                               const char *value)\r
101  {\r
102      char *term;\r
103 +    notmuch_log_t *log;\r
104  \r
105      if (value == NULL)\r
106         return NOTMUCH_PRIVATE_STATUS_NULL_POINTER;\r
107  \r
108 +    log=notmuch_database_get_log(message->notmuch);\r
109 +    if (log)\r
110 +       notmuch_log_words (log,"-", prefix_name, value,\r
111 +                          notmuch_message_get_message_id (message), NULL);\r
112 +\r
113      term = talloc_asprintf (message, "%s%s",\r
114                             _find_prefix (prefix_name), value);\r
115  \r
116 @@ -806,6 +823,7 @@ notmuch_status_t\r
117  notmuch_message_freeze (notmuch_message_t *message)\r
118  {\r
119      notmuch_status_t status;\r
120 +    notmuch_log_t* log;\r
121  \r
122      status = _notmuch_database_ensure_writable (message->notmuch);\r
123      if (status)\r
124 @@ -813,6 +831,10 @@ notmuch_message_freeze (notmuch_message_t *message)\r
125  \r
126      message->frozen++;\r
127  \r
128 +    log = notmuch_database_get_log (message->notmuch);\r
129 +    if (log)\r
130 +      notmuch_log_start_transaction (log);\r
131 +\r
132      return NOTMUCH_STATUS_SUCCESS;\r
133  }\r
134  \r
135 @@ -820,6 +842,7 @@ notmuch_status_t\r
136  notmuch_message_thaw (notmuch_message_t *message)\r
137  {\r
138      notmuch_status_t status;\r
139 +    notmuch_log_t* log;\r
140  \r
141      status = _notmuch_database_ensure_writable (message->notmuch);\r
142      if (status)\r
143 @@ -827,12 +850,19 @@ notmuch_message_thaw (notmuch_message_t *message)\r
144  \r
145      if (message->frozen > 0) {\r
146         message->frozen--;\r
147 +\r
148 +       log = notmuch_database_get_log (message->notmuch);\r
149 +       if (log)\r
150 +           notmuch_log_finish_transaction (log);\r
151 +\r
152         if (message->frozen == 0)\r
153             _notmuch_message_sync (message);\r
154 +\r
155         return NOTMUCH_STATUS_SUCCESS;\r
156      } else {\r
157         return NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW;\r
158      }\r
159 +\r
160  }\r
161  \r
162  void\r
163 -- \r
164 1.7.1\r
165 \r