1 Return-Path: <aclements@csail.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 1A5FD429E2F
\r
6 for <notmuch@notmuchmail.org>; Fri, 3 Oct 2014 07:19:45 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 PRYSfKQx5Qfk for <notmuch@notmuchmail.org>;
\r
16 Fri, 3 Oct 2014 07:19:38 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 3AE2A431FCF
\r
22 for <notmuch@notmuchmail.org>; Fri, 3 Oct 2014 07:19:26 -0700 (PDT)
\r
23 X-AuditID: 12074423-f799d6d00000337c-eb-542eb06dbcd7
\r
24 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
25 (using TLS with cipher AES256-SHA (256/256 bits))
\r
26 (Client did not present a certificate)
\r
27 by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP
\r
28 id A3.B6.13180.D60BE245; Fri, 3 Oct 2014 10:19:25 -0400 (EDT)
\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
30 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s93EJO7q018553;
\r
31 Fri, 3 Oct 2014 10:19:25 -0400
\r
32 Received: from drake.dyndns.org
\r
33 (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
34 [216.15.114.40]) (authenticated bits=0)
\r
35 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
36 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s93EJLNP023322
\r
37 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);
\r
38 Fri, 3 Oct 2014 10:19:24 -0400
\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.84)
\r
40 (envelope-from <aclements@csail.mit.edu>)
\r
41 id 1Xa3hZ-0002K7-9F; Fri, 03 Oct 2014 10:19:21 -0400
\r
42 From: Austin Clements <aclements@csail.mit.edu>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH 08/11] lib: Implement upgrade to ghost messages feature
\r
45 Date: Fri, 3 Oct 2014 10:19:15 -0400
\r
46 Message-Id: <1412345958-8278-9-git-send-email-aclements@csail.mit.edu>
\r
47 X-Mailer: git-send-email 2.1.0
\r
48 In-Reply-To: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu>
\r
49 References: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu>
\r
50 X-Brightmail-Tracker:
\r
51 H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrZu7QS/E4PBWaYvrN2cyOzB6PFt1
\r
52 izmAMYrLJiU1J7MstUjfLoErY+HO7YwFB2QqPk2fztTAuEusi5GTQ0LAROLbol5GCFtM4sK9
\r
53 9WxdjFwcQgKzmST+tm9ignA2MEqc+L4WKnObSWLxzXlgLUICSxglds/yALHZBPQlVqydxApi
\r
54 iwhIS+y8OxvI5uBgFlCT+NOlAhIWFnCXuPTuIgtImEVAVeLvOiuQMK+Am8SDf0eZII6Qk9iw
\r
55 +z/YdE6g8gt3n7JBbHKTWHWsm20CI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFumZ6uZkl
\r
56 eqkppZsYQSHD7qK8g/HPQaVDjAIcjEo8vB9u6IYIsSaWFVfmHmKU5GBSEuWtXKwXIsSXlJ9S
\r
57 mZFYnBFfVJqTWnyIUYKDWUmEd8FKoBxvSmJlVWpRPkxKmoNFSZx30w++ECGB9MSS1OzU1ILU
\r
58 IpisDAeHkgRv+3qgRsGi1PTUirTMnBKENBMHJ8hwHqDhYDW8xQWJucWZ6RD5U4yKUuK8D9cB
\r
59 JQRAEhmleXC9sJh+xSgO9IowbxdIOw8wHcB1vwIazAQ0+J29LsjgkkSElFQD45XCh7JZ/34X
\r
60 r9KWEC1/WbR0jkz8ybSzxW6fa9Oa1/Axf5x2NHSB97x3wgHbOhnuKZao7DnQfNXmlZhAp9+E
\r
61 greFqYenu02L0cridH20u1bcXnljJp+fdZuuLB+rxES2Z1sCZ53SF114KzP2ikePjvjvKXGt
\r
62 nkHhwdJPtqS7iCUVLE+NCedSYinOSDTUYi4qTgQAP4SZg8QCAAA=
\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: Fri, 03 Oct 2014 14:19:45 -0000
\r
77 From: Austin Clements <amdragon@mit.edu>
\r
79 Somehow this is the first upgrade pass that actually does *any* error
\r
80 checking, so this also adds the bit of necessary infrastructure to
\r
83 lib/database.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
\r
84 1 file changed, 62 insertions(+), 2 deletions(-)
\r
86 diff --git a/lib/database.cc b/lib/database.cc
\r
87 index fdcc526..ff6a7f6 100644
\r
88 --- a/lib/database.cc
\r
89 +++ b/lib/database.cc
\r
90 @@ -1231,6 +1231,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
91 notmuch_bool_t timer_is_active = FALSE;
\r
92 enum _notmuch_features target_features, new_features;
\r
93 notmuch_status_t status;
\r
94 + notmuch_private_status_t private_status;
\r
95 unsigned int count = 0, total = 0;
\r
97 status = _notmuch_database_ensure_writable (notmuch);
\r
98 @@ -1275,6 +1276,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
99 for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++)
\r
102 + if (new_features & NOTMUCH_FEATURE_GHOSTS) {
\r
103 + t_end = db->metadata_keys_end ("thread_id_");
\r
104 + for (t = db->metadata_keys_begin ("thread_id_"); t != t_end; ++t)
\r
108 /* Perform the upgrade in a transaction. */
\r
109 db->begin_transaction (true);
\r
110 @@ -1378,10 +1384,64 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
114 + /* Perform metadata upgrades. */
\r
116 + /* Prior to NOTMUCH_FEATURE_GHOSTS, thread IDs for missing
\r
117 + * messages were stored as database metadata. Change these to
\r
118 + * ghost messages.
\r
120 + if (new_features & NOTMUCH_FEATURE_GHOSTS) {
\r
121 + notmuch_message_t *message;
\r
122 + std::string message_id, thread_id;
\r
124 + t_end = db->metadata_keys_end (NOTMUCH_METADATA_THREAD_ID_PREFIX);
\r
125 + for (t = db->metadata_keys_begin (NOTMUCH_METADATA_THREAD_ID_PREFIX);
\r
126 + t != t_end; ++t) {
\r
127 + if (do_progress_notify) {
\r
128 + progress_notify (closure, (double) count / total);
\r
129 + do_progress_notify = 0;
\r
132 + message_id = (*t).substr (
\r
133 + strlen (NOTMUCH_METADATA_THREAD_ID_PREFIX));
\r
134 + thread_id = db->get_metadata (*t);
\r
136 + /* Create ghost message */
\r
137 + message = _notmuch_message_create_for_message_id (
\r
138 + notmuch, message_id.c_str (), &private_status);
\r
139 + if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) {
\r
140 + /* Document already exists; ignore the stored thread ID */
\r
141 + } else if (private_status ==
\r
142 + NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
143 + private_status = _notmuch_message_initialize_ghost (
\r
144 + message, thread_id.c_str ());
\r
145 + if (! private_status)
\r
146 + _notmuch_message_sync (message);
\r
149 + if (private_status) {
\r
151 + "Upgrade failed while creating ghost messages.\n");
\r
152 + status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
\r
156 + /* Clear saved metadata thread ID */
\r
157 + db->set_metadata (*t, "");
\r
163 + status = NOTMUCH_STATUS_SUCCESS;
\r
164 db->set_metadata ("features", _print_features (local, notmuch->features));
\r
165 db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));
\r
167 - db->commit_transaction ();
\r
169 + if (status == NOTMUCH_STATUS_SUCCESS)
\r
170 + db->commit_transaction ();
\r
172 + db->cancel_transaction ();
\r
174 if (timer_is_active) {
\r
175 /* Now stop the timer. */
\r
176 @@ -1397,7 +1457,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
179 talloc_free (local);
\r
180 - return NOTMUCH_STATUS_SUCCESS;
\r