1 Return-Path: <amthrax@drake.mit.edu>
\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 0B73C429E2F
\r
6 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:07:02 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 fnkPnziW2kGq for <notmuch@notmuchmail.org>;
\r
16 Sat, 11 Jun 2011 13:07:01 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id DA566429E2D
\r
20 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:07:00 -0700 (PDT)
\r
21 X-AuditID: 12074425-b7b82ae000000a2a-84-4df3cacc1b72
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 00.75.02602.CCAC3FD4; Sat, 11 Jun 2011 16:06:36 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK70Kg015055;
\r
27 Sat, 11 Jun 2011 16:07:00 -0400
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK6xtl006026
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sat, 11 Jun 2011 16:07:00 -0400 (EDT)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.76)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1QVUSR-0000II-8J; Sat, 11 Jun 2011 16:06:59 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 10/17] lib: Remove message document directly after removing
\r
42 Date: Sat, 11 Jun 2011 16:04:36 -0400
\r
43 Message-Id: <1307822683-848-11-git-send-email-amdragon@mit.edu>
\r
44 X-Mailer: git-send-email 1.7.5.1
\r
45 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
46 References: <87ei34rnc5.fsf@yoom.home.cworth.org>
\r
47 <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
48 X-Brightmail-Tracker:
\r
49 H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrHvm1Gdfg2kTtC2u35zJ7MDo8WzV
\r
50 LeYAxigum5TUnMyy1CJ9uwSujNb+1ywFm+UrTp1/z9rAeFKyi5GTQ0LAROJ28z8mCFtM4sK9
\r
51 9WxdjFwcQgL7GCXmve+DcjYwShyceogZwrnPJHHpYTs7hDOfUeLcwe+MIP1sAhoS2/YvB7NF
\r
52 BKQldt6dzdrFyMHBLKAm8adLBSQsLBAvsW/zDrB1LAKqEn+nXAcr5xWwl9i55D0jxBkKEleu
\r
53 zGMBsTmB4vMOXgWzhQTSJJbc2s0+gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0LvdzM
\r
54 Er3UlNJNjKCwYXdR3cE44ZDSIUYBDkYlHl7FtZ99hVgTy4orcw8xSnIwKYny6pwACvEl5adU
\r
55 ZiQWZ8QXleakFh9ilOBgVhLhXd/+yVeINyWxsiq1KB8mJc3BoiTOO19S3VdIID2xJDU7NbUg
\r
56 tQgmK8PBoSTBKwmMDyHBotT01Iq0zJwShDQTByfIcB6g4UdPAtXwFhck5hZnpkPkTzEaczze
\r
57 sOkQI0f7ZiApxJKXn5cqJc57H6RUAKQ0ozQPbhos9l8xigM9J8z7A6SKB5g24Oa9AlrFBLRK
\r
58 oBRsVUkiQkqqgZHD9/LM8ruX+KKmfc40iVgdH7LAPIb1+gXRz/KRHOmT/hSyKebcf+sboW0l
\r
59 d3hv19M1EXPt5zfe9hDnrrPff8zZo/tXrLiJ8PLUg+1aR1L3bCnb/2L+QaH1fvrhBlIfvJ1k
\r
60 OL+qbLe43n95Q8PEla2MLtvn/+N+dOx98kxLyZAXIYm3l4Yo+SqxFGckGmoxFxUnAgCCMVy9
\r
62 Cc: Austin Clements <amdragon@mit.edu>
\r
63 X-BeenThere: notmuch@notmuchmail.org
\r
64 X-Mailman-Version: 2.1.13
\r
66 List-Id: "Use and development of the notmuch mail system."
\r
67 <notmuch.notmuchmail.org>
\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
71 List-Post: <mailto:notmuch@notmuchmail.org>
\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
74 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
75 X-List-Received-Date: Sat, 11 Jun 2011 20:07:02 -0000
\r
77 Previously, notmuch_database_remove_message would remove the message
\r
78 file name, sync the change to the message document, re-find the
\r
79 message document, and then delete it if there were no more file names.
\r
80 An interruption after sync'ing would result in a file-name-less,
\r
81 permanently un-removable zombie message that would produce errors and
\r
82 odd results in searches. We could wrap this in an atomic section, but
\r
83 it's much simpler to eliminate the round-about approach and just
\r
84 delete the message document instead of sync'ing it if we removed the
\r
87 lib/database.cc | 25 +++++--------------------
\r
88 lib/message.cc | 16 ++++++++++++++++
\r
89 lib/notmuch-private.h | 3 +++
\r
90 3 files changed, 24 insertions(+), 20 deletions(-)
\r
92 diff --git a/lib/database.cc b/lib/database.cc
\r
93 index b766e94..9886622 100644
\r
94 --- a/lib/database.cc
\r
95 +++ b/lib/database.cc
\r
96 @@ -1747,7 +1747,6 @@ notmuch_status_t
\r
97 notmuch_database_remove_message (notmuch_database_t *notmuch,
\r
98 const char *filename)
\r
100 - Xapian::WritableDatabase *db;
\r
102 const char *prefix = _find_prefix ("file-direntry");
\r
103 char *direntry, *term;
\r
104 @@ -1761,8 +1760,6 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,
\r
106 local = talloc_new (notmuch);
\r
108 - db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
112 status = _notmuch_database_filename_to_direntry (local, notmuch,
\r
113 @@ -1785,23 +1782,11 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,
\r
114 return COERCE_STATUS (private_status,
\r
115 "Inconsistent document ID in datbase.");
\r
117 - _notmuch_message_remove_filename (message, filename);
\r
118 - _notmuch_message_sync (message);
\r
120 - /* Take care to find document after sync'ing filename removal. */
\r
121 - document = find_document_for_doc_id (notmuch, *i);
\r
122 - j = document.termlist_begin ();
\r
123 - j.skip_to (prefix);
\r
125 - /* Was this the last file-direntry in the message? */
\r
126 - if (j == document.termlist_end () ||
\r
127 - strncmp ((*j).c_str (), prefix, strlen (prefix)))
\r
129 - db->delete_document (document.get_docid ());
\r
130 - status = NOTMUCH_STATUS_SUCCESS;
\r
132 - status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
134 + status = _notmuch_message_remove_filename (message, filename);
\r
135 + if (status == NOTMUCH_STATUS_SUCCESS)
\r
136 + _notmuch_message_delete (message);
\r
137 + else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
\r
138 + _notmuch_message_sync (message);
\r
140 } catch (const Xapian::Error &error) {
\r
141 fprintf (stderr, "Error: A Xapian exception occurred removing message: %s\n",
\r
142 diff --git a/lib/message.cc b/lib/message.cc
\r
143 index 5120b3a..9de60d2 100644
\r
144 --- a/lib/message.cc
\r
145 +++ b/lib/message.cc
\r
146 @@ -797,6 +797,22 @@ _notmuch_message_sync (notmuch_message_t *message)
\r
147 db->replace_document (message->doc_id, message->doc);
\r
150 +/* Delete a message document from the database. */
\r
152 +_notmuch_message_delete (notmuch_message_t *message)
\r
154 + notmuch_status_t status;
\r
155 + Xapian::WritableDatabase *db;
\r
157 + status = _notmuch_database_ensure_writable (message->notmuch);
\r
161 + db = static_cast <Xapian::WritableDatabase *> (message->notmuch->xapian_db);
\r
162 + db->delete_document (message->doc_id);
\r
163 + return NOTMUCH_STATUS_SUCCESS;
\r
166 /* Ensure that 'message' is not holding any file object open. Future
\r
167 * calls to various functions will still automatically open the
\r
168 * message file as needed.
\r
169 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
170 index 02e24ee..d319530 100644
\r
171 --- a/lib/notmuch-private.h
\r
172 +++ b/lib/notmuch-private.h
\r
173 @@ -293,6 +293,9 @@ _notmuch_message_set_date (notmuch_message_t *message,
\r
175 _notmuch_message_sync (notmuch_message_t *message);
\r
178 +_notmuch_message_delete (notmuch_message_t *message);
\r
181 _notmuch_message_close (notmuch_message_t *message);
\r