"snoozing" with notmuch?
[notmuch-archives.git] / 50 / ec8fb50e378c19ca417d2dcb00c30715cda30d
1 Return-Path: <amdragon@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 1D84A429E31\r
6         for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:26 -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.3\r
10 X-Spam-Level: \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 Kdp6lYX-XkN4 for <notmuch@notmuchmail.org>;\r
16         Sat, 26 Jul 2014 20:53:18 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
18         [18.7.68.35])\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 F0087431FC9\r
22         for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:07 -0700 (PDT)\r
23 X-AuditID: 12074423-f79bf6d000007580-e9-53d477a2cd15\r
24 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\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 5D.64.30080.2A774D35; Sat, 26 Jul 2014 23:53:07 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r3LG009549; \r
31         Sat, 26 Jul 2014 23:53:03 -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 s6R3r0Wi016396\r
37         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
38         Sat, 26 Jul 2014 23:53:02 -0400\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
40         (envelope-from <amdragon@mit.edu>)\r
41         id 1XBFW8-00051I-9X; Sat, 26 Jul 2014 23:53:00 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 05/14] lib: Database version 3: Introduce fine-grained\r
45         "features"\r
46 Date: Sat, 26 Jul 2014 23:52:44 -0400\r
47 Message-Id: <1406433173-19169-6-git-send-email-amdragon@mit.edu>\r
48 X-Mailer: git-send-email 2.0.0\r
49 In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
50 References: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixG6nrru4/EqwwZ52RovrN2cyOzB6PFt1\r
53         izmAMYrLJiU1J7MstUjfLoEr4+qCHpaCXWUVV0/cY25gfB7dxcjJISFgItHxdTUrhC0mceHe\r
54         erYuRi4OIYHZTBK3rmxih3A2MkrMeLCVCcK5wyQx9eRZVghnLqPEtmXb2EH62QQ0JLbtX84I\r
55         YosISEvsvDsbqIiDg1lATeJPlwpIWFggUGLzwadsIDaLgKrEvSVzWUBsXgEHiQmnXjJCnCEn\r
56         0XDjE1gNp4CjxPFnJ9hAxggB1dy6lDiBkX8BI8MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXTO9\r
57         3MwSvdSU0k2M4KBxUd7B+Oeg0iFGAQ5GJR7eDLYrwUKsiWXFlbmHGCU5mJREefebAYX4kvJT\r
58         KjMSizPii0pzUosPMUpwMCuJ8AoVA+V4UxIrq1KL8mFS0hwsSuK8b62tgoUE0hNLUrNTUwtS\r
59         i2CyMhwcShK808uAGgWLUtNTK9Iyc0oQ0kwcnCDDeYCGbygFGV5ckJhbnJkOkT/FqCglzvsL\r
60         JCEAksgozYPrhUX1K0ZxoFeEeVlBVvAAEwJc9yugwUxAg1n8L4MMLklESEk1MC4sjv+4PvD9\r
61         MWEbjtK9HmJHim5lZQRy9/C/106Nafzy3EFtfcdjx/rjH5q+pEvJFQTUtjAlBtq6rKxZ0p92\r
62         8otX35sd9ia7Z++qXT5rPfeOKy1bLq58objjtu5BhR0G/y75vdp2ZMqE2dJtRevNzcpFzjBv\r
63         27iO588fpoSnBwwl3x8PmH93zk4lluKMREMt5qLiRAAXcORqxQIAAA==\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Sun, 27 Jul 2014 03:53:26 -0000\r
77 \r
78 Previously, our database schema was versioned by a single number.\r
79 Each database schema change had to occur "atomically" in Notmuch's\r
80 development history: before some commit, Notmuch used version N, after\r
81 that commit, it used version N+1.  Hence, each new schema version\r
82 could introduce only one change, the task of developing a schema\r
83 change fell on a single person, and it all had to happen and be\r
84 perfect in a single commit series.  This made introducing a new schema\r
85 version hard.  We've seen only two schema changes in the history of\r
86 Notmuch.\r
87 \r
88 This commit introduces database schema version 3; hopefully the last\r
89 schema version we'll need for a while.  With this version, we switch\r
90 from a single version number to "features": a set of named,\r
91 independent aspects of the database schema.\r
92 \r
93 Features should make backwards compatibility easier.  For many things,\r
94 it should be easy to support databases both with and without a\r
95 feature, which will allow us to make upgrades optional and will enable\r
96 "unstable" features that can be developed and tested over time.\r
97 \r
98 Features also make forwards compatibility easier.  The features\r
99 recorded in a database include "compatibility flags," which can\r
100 indicate to an older version of Notmuch when it must support a given\r
101 feature to open the database for read or for write.  This lets us\r
102 replace the old vague "I don't recognize this version, so something\r
103 might go wrong, but I promise to try my best" warnings upon opening a\r
104 database with an unknown version with precise errors.  If a database\r
105 is safe to open for read/write despite unknown features, an older\r
106 version will know that and issue no message at all.  If the database\r
107 is not safe to open for read/write because of unknown features, an\r
108 older version will know that, too, and can tell the user exactly which\r
109 required features it lacks support for.\r
110 ---\r
111  lib/database-private.h |  56 +++++++++++++++\r
112  lib/database.cc        | 189 +++++++++++++++++++++++++++++++++++++++++--------\r
113  2 files changed, 214 insertions(+), 31 deletions(-)\r
114 \r
115 diff --git a/lib/database-private.h b/lib/database-private.h\r
116 index d3e65fd..323b9fe 100644\r
117 --- a/lib/database-private.h\r
118 +++ b/lib/database-private.h\r
119 @@ -46,6 +46,11 @@ struct _notmuch_database {\r
120      int atomic_nesting;\r
121      Xapian::Database *xapian_db;\r
122  \r
123 +    /* Bit mask of features used by this database.  Features are\r
124 +     * named, independent aspects of the database schema.  This is a\r
125 +     * bitwise-OR of NOTMUCH_FEATURE_* values (below). */\r
126 +    unsigned int features;\r
127 +\r
128      unsigned int last_doc_id;\r
129      uint64_t last_thread_id;\r
130  \r
131 @@ -55,6 +60,57 @@ struct _notmuch_database {\r
132      Xapian::ValueRangeProcessor *date_range_processor;\r
133  };\r
134  \r
135 +/* Bit masks for _notmuch_database::features. */\r
136 +enum {\r
137 +    /* If set, file names are stored in "file-direntry" terms.  If\r
138 +     * unset, file names are stored in document data.\r
139 +     *\r
140 +     * Introduced: version 1.  Implementation support: both for read;\r
141 +     * required for write. */\r
142 +    NOTMUCH_FEATURE_FILE_TERMS = 1 << 0,\r
143 +\r
144 +    /* If set, directory timestamps are stored in documents with\r
145 +     * XDIRECTORY terms and relative paths.  If unset, directory\r
146 +     * timestamps are stored in documents with XTIMESTAMP terms and\r
147 +     * absolute paths.\r
148 +     *\r
149 +     * Introduced: version 1.  Implementation support: required. */\r
150 +    NOTMUCH_FEATURE_DIRECTORY_DOCS = 1 << 1,\r
151 +\r
152 +    /* If set, the from, subject, and message-id headers are stored in\r
153 +     * message document values.  If unset, message documents *may*\r
154 +     * have these values, but if the value is empty, it must be\r
155 +     * retrieved from the message file.\r
156 +     *\r
157 +     * Introduced: optional in version 1, required as of version 3.\r
158 +     * Implementation support: both.\r
159 +     */\r
160 +    NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES = 1 << 2,\r
161 +\r
162 +    /* If set, folder terms are boolean and path terms exist.  If\r
163 +     * unset, folder terms are probabilistic and stemmed and path\r
164 +     * terms do not exist.\r
165 +     *\r
166 +     * Introduced: version 2.  Implementation support: required. */\r
167 +    NOTMUCH_FEATURE_BOOL_FOLDER = 1 << 3,\r
168 +};\r
169 +\r
170 +/* Prior to database version 3, features were implied by the database\r
171 + * version number, so hard-code them for earlier versions. */\r
172 +#define NOTMUCH_FEATURES_V0 (0)\r
173 +#define NOTMUCH_FEATURES_V1 (NOTMUCH_FEATURES_V0 | NOTMUCH_FEATURE_FILE_TERMS | \\r
174 +                            NOTMUCH_FEATURE_DIRECTORY_DOCS)\r
175 +#define NOTMUCH_FEATURES_V2 (NOTMUCH_FEATURES_V1 | NOTMUCH_FEATURE_BOOL_FOLDER)\r
176 +\r
177 +/* Current database features.  If any of these are missing from a\r
178 + * database, request an upgrade.\r
179 + * NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES is not included because\r
180 + * upgrade doesn't currently introduce the feature (though brand new\r
181 + * databases will have it). */\r
182 +#define NOTMUCH_FEATURES_CURRENT \\r
183 +    (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_DIRECTORY_DOCS | \\r
184 +     NOTMUCH_FEATURE_BOOL_FOLDER)\r
185 +\r
186  /* Return the list of terms from the given iterator matching a prefix.\r
187   * The prefix will be stripped from the strings in the returned list.\r
188   * The list will be allocated using ctx as the talloc context.\r
189 diff --git a/lib/database.cc b/lib/database.cc\r
190 index 45c4260..03eef3e 100644\r
191 --- a/lib/database.cc\r
192 +++ b/lib/database.cc\r
193 @@ -20,6 +20,7 @@\r
194  \r
195  #include "database-private.h"\r
196  #include "parse-time-vrp.h"\r
197 +#include "string-util.h"\r
198  \r
199  #include <iostream>\r
200  \r
201 @@ -42,7 +43,7 @@ typedef struct {\r
202      const char *prefix;\r
203  } prefix_t;\r
204  \r
205 -#define NOTMUCH_DATABASE_VERSION 2\r
206 +#define NOTMUCH_DATABASE_VERSION 3\r
207  \r
208  #define STRINGIFY(s) _SUB_STRINGIFY(s)\r
209  #define _SUB_STRINGIFY(s) #s\r
210 @@ -151,6 +152,17 @@ typedef struct {\r
211   *                     changes are made to the database (such as by\r
212   *                     indexing new fields).\r
213   *\r
214 + *     features        The set of features supported by this\r
215 + *                     database. This consists of a set of\r
216 + *                     '\n'-separated lines, where each is a feature\r
217 + *                     name, a '\t', and compatibility flags.  If the\r
218 + *                     compatibility flags contain 'w', then the\r
219 + *                     opener must support this feature to safely\r
220 + *                     write this database.  If the compatibility\r
221 + *                     flags contain 'r', then the opener must\r
222 + *                     support this feature to read this database.\r
223 + *                     Introduced in database version 3.\r
224 + *\r
225   *     last_thread_id  The last thread ID generated. This is stored\r
226   *                     as a 16-byte hexadecimal ASCII representation\r
227   *                     of a 64-bit unsigned integer. The first ID\r
228 @@ -226,6 +238,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
229      { "subject",               "XSUBJECT"},\r
230  };\r
231  \r
232 +\r
233  const char *\r
234  _find_prefix (const char *name)\r
235  {\r
236 @@ -251,6 +264,25 @@ _find_prefix (const char *name)\r
237      return "";\r
238  }\r
239  \r
240 +static const struct\r
241 +{\r
242 +    /* NOTMUCH_FEATURE_* value. */\r
243 +    unsigned int value;\r
244 +    /* Feature name as it appears in the database.  This name should\r
245 +     * be appropriate for displaying to the user if an older version\r
246 +     * of notmuch doesn't support this feature. */\r
247 +    const char *name;\r
248 +    /* Compatibility flags when this feature is declared. */\r
249 +    const char *flags;\r
250 +} feature_names[] = {\r
251 +    {NOTMUCH_FEATURE_FILE_TERMS,             "file terms", "rw"},\r
252 +    {NOTMUCH_FEATURE_DIRECTORY_DOCS,         "directory documents", "rw"},\r
253 +    /* Header values are not required for reading a database because a\r
254 +     * reader can just refer to the message file. */\r
255 +    {NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES, "from/subject/ID values", "w"},\r
256 +    {NOTMUCH_FEATURE_BOOL_FOLDER,            "boolean folder terms", "rw"},\r
257 +};\r
258 +\r
259  const char *\r
260  notmuch_status_to_string (notmuch_status_t status)\r
261  {\r
262 @@ -591,6 +623,11 @@ notmuch_database_create (const char *path, notmuch_database_t **database)\r
263                                     &notmuch);\r
264      if (status)\r
265         goto DONE;\r
266 +\r
267 +    /* Upgrade doesn't add this feature to existing databases, but new\r
268 +     * databases have it. */\r
269 +    notmuch->features |= NOTMUCH_FEATURE_FROM_SUBJECT_ID_VALUES;\r
270 +\r
271      status = notmuch_database_upgrade (notmuch, NULL, NULL);\r
272      if (status) {\r
273         notmuch_database_close(notmuch);\r
274 @@ -619,6 +656,80 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
275      return NOTMUCH_STATUS_SUCCESS;\r
276  }\r
277  \r
278 +/* Parse a database features string from the given database version.\r
279 + *\r
280 + * For version < 3, this ignores the features string and returns a\r
281 + * hard-coded set of features.\r
282 + *\r
283 + * If there are unrecognized features that are required to open the\r
284 + * database in mode (which should be 'r' or 'w'), return a\r
285 + * comma-separated list of unrecognized but required features in\r
286 + * *incompat_out, which will be allocated from ctx.\r
287 + */\r
288 +static unsigned int\r
289 +_parse_features (const void *ctx, const char *features, unsigned int version,\r
290 +                char mode, char **incompat_out)\r
291 +{\r
292 +    unsigned int res = 0, namelen, i;\r
293 +    size_t llen = 0;\r
294 +    const char *flags;\r
295 +\r
296 +    /* Prior to database version 3, features were implied by the\r
297 +     * version number. */\r
298 +    if (version == 0)\r
299 +       return NOTMUCH_FEATURES_V0;\r
300 +    else if (version == 1)\r
301 +       return NOTMUCH_FEATURES_V1;\r
302 +    else if (version == 2)\r
303 +       return NOTMUCH_FEATURES_V2;\r
304 +\r
305 +    /* Parse the features string */\r
306 +    while ((features = strtok_len_c (features + llen, "\n", &llen)) != NULL) {\r
307 +       flags = strchr (features, '\t');\r
308 +       if (! flags || flags > features + llen)\r
309 +           continue;\r
310 +       namelen = flags - features;\r
311 +\r
312 +       for (i = 0; i < ARRAY_SIZE (feature_names); ++i) {\r
313 +           if (strlen (feature_names[i].name) == namelen &&\r
314 +               strncmp (feature_names[i].name, features, namelen) == 0) {\r
315 +               res |= feature_names[i].value;\r
316 +               break;\r
317 +           }\r
318 +       }\r
319 +\r
320 +       if (i == ARRAY_SIZE (feature_names)) {\r
321 +           /* Unrecognized feature */\r
322 +           const char *have = strchr (flags, mode);\r
323 +           if (have && have < features + llen) {\r
324 +               /* This feature is required to access this database in\r
325 +                * 'mode', but we don't understand it. */\r
326 +               if (! *incompat_out)\r
327 +                   *incompat_out = talloc_strdup (ctx, "");\r
328 +               *incompat_out = talloc_asprintf_append_buffer (\r
329 +                   *incompat_out, "%s%.*s", **incompat_out ? ", " : "",\r
330 +                   namelen, features);\r
331 +           }\r
332 +       }\r
333 +    }\r
334 +\r
335 +    return res;\r
336 +}\r
337 +\r
338 +static char *\r
339 +_print_features (const void *ctx, unsigned int features)\r
340 +{\r
341 +    unsigned int i;\r
342 +    char *res = talloc_strdup (ctx, "");\r
343 +\r
344 +    for (i = 0; i < ARRAY_SIZE (feature_names); ++i)\r
345 +       if (features & feature_names[i].value)\r
346 +           res = talloc_asprintf_append_buffer (\r
347 +               res, "%s\t%s\n", feature_names[i].name, feature_names[i].flags);\r
348 +\r
349 +    return res;\r
350 +}\r
351 +\r
352  notmuch_status_t\r
353  notmuch_database_open (const char *path,\r
354                        notmuch_database_mode_t mode,\r
355 @@ -627,7 +738,7 @@ notmuch_database_open (const char *path,\r
356      notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
357      void *local = talloc_new (NULL);\r
358      notmuch_database_t *notmuch = NULL;\r
359 -    char *notmuch_path, *xapian_path;\r
360 +    char *notmuch_path, *xapian_path, *incompat_features;\r
361      struct stat st;\r
362      int err;\r
363      unsigned int i, version;\r
364 @@ -686,39 +797,51 @@ notmuch_database_open (const char *path,\r
365         if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {\r
366             notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,\r
367                                                                Xapian::DB_CREATE_OR_OPEN);\r
368 -           version = notmuch_database_get_version (notmuch);\r
369 -\r
370 -           if (version > NOTMUCH_DATABASE_VERSION) {\r
371 -               fprintf (stderr,\r
372 -                        "Error: Notmuch database at %s\n"\r
373 -                        "       has a newer database format version (%u) than supported by this\n"\r
374 -                        "       version of notmuch (%u). Refusing to open this database in\n"\r
375 -                        "       read-write mode.\n",\r
376 -                        notmuch_path, version, NOTMUCH_DATABASE_VERSION);\r
377 -               notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
378 -               notmuch_database_destroy (notmuch);\r
379 -               notmuch = NULL;\r
380 -               status = NOTMUCH_STATUS_FILE_ERROR;\r
381 -               goto DONE;\r
382 -           }\r
383 -\r
384 -           if (version < NOTMUCH_DATABASE_VERSION)\r
385 -               notmuch->needs_upgrade = TRUE;\r
386         } else {\r
387             notmuch->xapian_db = new Xapian::Database (xapian_path);\r
388 -           version = notmuch_database_get_version (notmuch);\r
389 -           if (version > NOTMUCH_DATABASE_VERSION)\r
390 -           {\r
391 -               fprintf (stderr,\r
392 -                        "Warning: Notmuch database at %s\n"\r
393 -                        "         has a newer database format version (%u) than supported by this\n"\r
394 -                        "         version of notmuch (%u). Some operations may behave incorrectly,\n"\r
395 -                        "         (but the database will not be harmed since it is being opened\n"\r
396 -                        "         in read-only mode).\n",\r
397 -                        notmuch_path, version, NOTMUCH_DATABASE_VERSION);\r
398 -           }\r
399         }\r
400  \r
401 +       /* Check version.  As of database version 3, we represent\r
402 +        * changes in terms of features, so assume a version bump\r
403 +        * means a dramatically incompatible change. */\r
404 +       version = notmuch_database_get_version (notmuch);\r
405 +       if (version > NOTMUCH_DATABASE_VERSION) {\r
406 +           fprintf (stderr,\r
407 +                    "Error: Notmuch database at %s\n"\r
408 +                    "       has a newer database format version (%u) than supported by this\n"\r
409 +                    "       version of notmuch (%u).\n",\r
410 +                    notmuch_path, version, NOTMUCH_DATABASE_VERSION);\r
411 +           notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
412 +           notmuch_database_destroy (notmuch);\r
413 +           notmuch = NULL;\r
414 +           status = NOTMUCH_STATUS_FILE_ERROR;\r
415 +           goto DONE;\r
416 +       }\r
417 +\r
418 +       /* Check features. */\r
419 +       incompat_features = NULL;\r
420 +       notmuch->features = _parse_features (\r
421 +           local, notmuch->xapian_db->get_metadata ("features").c_str (),\r
422 +           version, mode == NOTMUCH_DATABASE_MODE_READ_WRITE ? 'w' : 'r',\r
423 +           &incompat_features);\r
424 +       if (incompat_features) {\r
425 +           fprintf (stderr,\r
426 +                    "Error: Notmuch database at %s\n"\r
427 +                    "       requires features (%s)\n"\r
428 +                    "       not supported by this version of notmuch.\n",\r
429 +                    notmuch_path, incompat_features);\r
430 +           notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
431 +           notmuch_database_destroy (notmuch);\r
432 +           notmuch = NULL;\r
433 +           status = NOTMUCH_STATUS_FILE_ERROR;\r
434 +           goto DONE;\r
435 +       }\r
436 +\r
437 +       /* Do we want an upgrade? */\r
438 +       if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE &&\r
439 +           NOTMUCH_FEATURES_CURRENT & ~notmuch->features)\r
440 +           notmuch->needs_upgrade = TRUE;\r
441 +\r
442         notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid ();\r
443         last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id");\r
444         if (last_thread_id.empty ()) {\r
445 @@ -1077,6 +1200,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
446                                                    double progress),\r
447                           void *closure)\r
448  {\r
449 +    void *local = talloc_new (NULL);\r
450      Xapian::WritableDatabase *db;\r
451      struct sigaction action;\r
452      struct itimerval timerval;\r
453 @@ -1226,6 +1350,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
454         notmuch_query_destroy (query);\r
455      }\r
456  \r
457 +    notmuch->features |= NOTMUCH_FEATURES_CURRENT;\r
458 +    db->set_metadata ("features", _print_features (local, notmuch->features));\r
459      db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));\r
460      db->flush ();\r
461  \r
462 @@ -1302,6 +1428,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
463         sigaction (SIGALRM, &action, NULL);\r
464      }\r
465  \r
466 +    talloc_free (local);\r
467      return NOTMUCH_STATUS_SUCCESS;\r
468  }\r
469  \r
470 -- \r
471 2.0.0\r
472 \r