1 Return-Path: <jani@nikula.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 45D0A429E37
\r
6 for <notmuch@notmuchmail.org>; Sun, 1 Dec 2013 05:14:21 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id wILZwBwNO8cq for <notmuch@notmuchmail.org>;
\r
17 Sun, 1 Dec 2013 05:14:16 -0800 (PST)
\r
18 Received: from mail-ea0-f176.google.com (mail-ea0-f176.google.com
\r
19 [209.85.215.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id B2E91431FDC
\r
22 for <notmuch@notmuchmail.org>; Sun, 1 Dec 2013 05:14:14 -0800 (PST)
\r
23 Received: by mail-ea0-f176.google.com with SMTP id h14so8145704eaj.35
\r
24 for <notmuch@notmuchmail.org>; Sun, 01 Dec 2013 05:14:13 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 :references:in-reply-to:references;
\r
29 bh=YAsMLe1afCIk4XzUWa68mP7QmhaTsh/rPVEI/q/voNE=;
\r
30 b=HvdnWKAJvijwp9w0HMSnWPUOitHmMWITqOET/4Rq1Mp8CQUhz+2iOfm1w2yexwtSvI
\r
31 n+RJoAGbWiV7fuZBQ4w60XUGOt8RPL6FDBTfqUiO2geEIaa1Eu0gZZtwHe2UxAZeRMwn
\r
32 NkumMlfhje6nxjG7qFZ2sNNBoBBjceo/qZyekKAGwhgZUO8xG8LCLZx3pwQzofq+LGlp
\r
33 IJXknT8/oq5x/2mAcTbXIvN9JtNplrm16maNCfrqRi8rMGeor4y6zO2QzSuLb2Ro/XGS
\r
34 irLCivai/AX0Tn1dqYCb9Fztrh+erWHIOAGdIPG1PN1VRUTVGtXUYq9FbcR/4icnceMh
\r
37 ALoCoQmzcCntAWbCg4RzEfyQY33iR0xvoUvhb6jp1jxG2hPeFRmBGYNEoOuM59QFRO3Em1EPgKxm
\r
38 X-Received: by 10.15.86.75 with SMTP id h51mr75434eez.44.1385903653491;
\r
39 Sun, 01 Dec 2013 05:14:13 -0800 (PST)
\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
42 by mx.google.com with ESMTPSA id m1sm54883447eeg.0.2013.12.01.05.14.11
\r
43 for <multiple recipients>
\r
44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
45 Sun, 01 Dec 2013 05:14:12 -0800 (PST)
\r
46 From: Jani Nikula <jani@nikula.org>
\r
47 To: notmuch@notmuchmail.org
\r
48 Subject: [PATCH 2/2] lib: introduce notmuch_database_new for initializing a
\r
50 Date: Sun, 1 Dec 2013 15:14:00 +0200
\r
52 <fc7ecd990e55fcfba17de4d71e8823c98760f9ce.1385903109.git.jani@nikula.org>
\r
53 X-Mailer: git-send-email 1.8.4.2
\r
54 In-Reply-To: <cover.1385903109.git.jani@nikula.org>
\r
55 References: <cover.1385903109.git.jani@nikula.org>
\r
56 In-Reply-To: <cover.1385903109.git.jani@nikula.org>
\r
57 References: <cover.1385903109.git.jani@nikula.org>
\r
58 X-BeenThere: notmuch@notmuchmail.org
\r
59 X-Mailman-Version: 2.1.13
\r
61 List-Id: "Use and development of the notmuch mail system."
\r
62 <notmuch.notmuchmail.org>
\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
66 List-Post: <mailto:notmuch@notmuchmail.org>
\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
70 X-List-Received-Date: Sun, 01 Dec 2013 13:14:21 -0000
\r
72 There is a need for setting options before opening a database, such as
\r
73 setting a logging function to use instead of writing to stdout or
\r
74 stderr. It would be possible to do this by adding new parameters to
\r
75 notmuch_database_create and notmuch_database_open, but maintaining a
\r
76 backwards compatible API and ABI when new options are added becomes
\r
79 Instead, split the opaque database object creation from
\r
80 notmuch_database_create and notmuch_database_open into a new
\r
81 notmuch_database_new call, to allow operations on the handle before
\r
82 create and open. This creates API and ABI breakage now, but allows
\r
83 easier future extensions.
\r
85 The notmuch_database_new call becomes a natural pair to the already
\r
86 existing notmuch_database_destroy, and it should be possible to call
\r
87 open/close multiple times using an initialized handle.
\r
89 lib/database.cc | 64 ++++++++++++++++++++++++++++------------------------
\r
90 lib/notmuch.h | 52 ++++++++++++++++++++++++++++++++----------
\r
91 notmuch-compact.c | 11 ++++++++-
\r
92 notmuch-count.c | 10 ++++++--
\r
93 notmuch-dump.c | 10 ++++++--
\r
94 notmuch-insert.c | 10 ++++++--
\r
95 notmuch-new.c | 14 +++++++-----
\r
96 notmuch-reply.c | 10 ++++++--
\r
97 notmuch-restore.c | 10 ++++++--
\r
98 notmuch-search.c | 10 ++++++--
\r
99 notmuch-show.c | 10 ++++++--
\r
100 notmuch-tag.c | 10 ++++++--
\r
101 test/random-corpus.c | 10 ++++++--
\r
102 test/symbol-test.cc | 3 ++-
\r
103 14 files changed, 166 insertions(+), 68 deletions(-)
\r
105 diff --git a/lib/database.cc b/lib/database.cc
\r
106 index 98e2c31..386b93a 100644
\r
107 --- a/lib/database.cc
\r
108 +++ b/lib/database.cc
\r
109 @@ -539,10 +539,21 @@ parse_references (void *ctx,
\r
113 -notmuch_database_create (const char *path, notmuch_database_t **database)
\r
114 +notmuch_database_new (notmuch_database_t **notmuch)
\r
116 + /* Note: try to avoid error conditions! No error printing! */
\r
118 + *notmuch = talloc_zero (NULL, notmuch_database_t);
\r
120 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
122 + return NOTMUCH_STATUS_SUCCESS;
\r
126 +notmuch_database_create (notmuch_database_t *notmuch, const char *path)
\r
128 notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
\r
129 - notmuch_database_t *notmuch = NULL;
\r
130 char *notmuch_path = NULL;
\r
133 @@ -579,25 +590,18 @@ notmuch_database_create (const char *path, notmuch_database_t **database)
\r
137 - status = notmuch_database_open (path,
\r
138 - NOTMUCH_DATABASE_MODE_READ_WRITE,
\r
140 + status = notmuch_database_open (notmuch, path,
\r
141 + NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
144 status = notmuch_database_upgrade (notmuch, NULL, NULL);
\r
147 notmuch_database_close(notmuch);
\r
153 talloc_free (notmuch_path);
\r
156 - *database = notmuch;
\r
158 - talloc_free (notmuch);
\r
162 @@ -612,14 +616,15 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
\r
163 return NOTMUCH_STATUS_SUCCESS;
\r
167 + * XXX: error handling should clean up *all* state created!
\r
170 -notmuch_database_open (const char *path,
\r
171 - notmuch_database_mode_t mode,
\r
172 - notmuch_database_t **database)
\r
173 +notmuch_database_open (notmuch_database_t *notmuch, const char *path,
\r
174 + notmuch_database_mode_t mode)
\r
176 notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
\r
177 void *local = talloc_new (NULL);
\r
178 - notmuch_database_t *notmuch = NULL;
\r
179 char *notmuch_path, *xapian_path;
\r
182 @@ -663,7 +668,6 @@ notmuch_database_open (const char *path,
\r
186 - notmuch = talloc_zero (NULL, notmuch_database_t);
\r
187 notmuch->exception_reported = FALSE;
\r
188 notmuch->path = talloc_strdup (notmuch, path);
\r
190 @@ -689,8 +693,7 @@ notmuch_database_open (const char *path,
\r
191 " read-write mode.\n",
\r
192 notmuch_path, version, NOTMUCH_DATABASE_VERSION);
\r
193 notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;
\r
194 - notmuch_database_destroy (notmuch);
\r
196 + notmuch_database_close (notmuch);
\r
197 status = NOTMUCH_STATUS_FILE_ERROR;
\r
200 @@ -752,21 +755,19 @@ notmuch_database_open (const char *path,
\r
201 } catch (const Xapian::Error &error) {
\r
202 fprintf (stderr, "A Xapian exception occurred opening database: %s\n",
\r
203 error.get_msg().c_str());
\r
204 - notmuch_database_destroy (notmuch);
\r
206 + notmuch_database_close (notmuch);
\r
207 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
211 talloc_free (local);
\r
214 - *database = notmuch;
\r
216 - talloc_free (notmuch);
\r
221 + * XXX: close should clean up *all* state created by open/create!
\r
224 notmuch_database_close (notmuch_database_t *notmuch)
\r
226 @@ -869,7 +870,8 @@ public:
\r
227 * compaction process to protect data integrity.
\r
230 -notmuch_database_compact (const char *path,
\r
231 +notmuch_database_compact (notmuch_database_t *notmuch,
\r
232 + const char *path,
\r
233 const char *backup_path,
\r
234 notmuch_compact_status_cb_t status_cb,
\r
236 @@ -877,7 +879,6 @@ notmuch_database_compact (const char *path,
\r
238 char *notmuch_path, *xapian_path, *compact_xapian_path;
\r
239 notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
240 - notmuch_database_t *notmuch = NULL;
\r
241 struct stat statbuf;
\r
242 notmuch_bool_t keep_backup;
\r
244 @@ -885,7 +886,8 @@ notmuch_database_compact (const char *path,
\r
246 return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
248 - ret = notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much);
\r
249 + ret = notmuch_database_open (notmuch, path,
\r
250 + NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
254 @@ -971,8 +973,9 @@ notmuch_database_compact (const char *path,
\r
258 + /* XXX: error handling */
\r
260 - ret = notmuch_database_destroy (notmuch);
\r
261 + ret = notmuch_database_close (notmuch);
\r
263 talloc_free (local);
\r
265 @@ -980,7 +983,8 @@ notmuch_database_compact (const char *path,
\r
269 -notmuch_database_compact (unused (const char *path),
\r
270 +notmuch_database_compact (unused (notmuch_database_t *notmuch),
\r
271 + unused (const char *path),
\r
272 unused (const char *backup_path),
\r
273 unused (notmuch_compact_status_cb_t status_cb),
\r
274 unused (void *closure))
\r
275 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
276 index dbdce86..cd58d15 100644
\r
277 --- a/lib/notmuch.h
\r
278 +++ b/lib/notmuch.h
\r
279 @@ -149,6 +149,28 @@ typedef struct _notmuch_tags notmuch_tags_t;
\r
280 typedef struct _notmuch_directory notmuch_directory_t;
\r
281 typedef struct _notmuch_filenames notmuch_filenames_t;
\r
283 +/* Initialize a new, empty database handle.
\r
285 + * The database handle is required for creating, opening, and
\r
286 + * compacting a database. For further database operations, the
\r
287 + * database needs to be created or opened.
\r
289 + * After a successful call to notmuch_database_new, the returned
\r
290 + * database handle will remain in memory, so the caller should call
\r
291 + * notmuch_database_destroy when finished with the database handle.
\r
293 + * In case of any failure, this function returns an error status and
\r
294 + * sets *notmuch to NULL.
\r
298 + * NOTMUCH_STATUS_SUCCESS: Successfully created the database object.
\r
300 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
\r
303 +notmuch_database_new (notmuch_database_t **notmuch);
\r
305 /* Create a new, empty notmuch database located at 'path'.
\r
307 * The path should be a top-level directory to a collection of
\r
308 @@ -156,9 +178,9 @@ typedef struct _notmuch_filenames notmuch_filenames_t;
\r
309 * create a new ".notmuch" directory within 'path' where notmuch will
\r
312 - * After a successful call to notmuch_database_create, the returned
\r
313 - * database will be open so the caller should call
\r
314 - * notmuch_database_destroy when finished with it.
\r
315 + * After a successful call to notmuch_database_create, the database
\r
316 + * will be open so the caller should call notmuch_database_close (or
\r
317 + * notmuch_database_destroy) when finished with the database.
\r
319 * The database will not yet have any data in it
\r
320 * (notmuch_database_create itself is a very cheap function). Messages
\r
321 @@ -166,7 +188,8 @@ typedef struct _notmuch_filenames notmuch_filenames_t;
\r
322 * notmuch_database_add_message.
\r
324 * In case of any failure, this function returns an error status and
\r
325 - * sets *database to NULL (after printing an error message on stderr).
\r
326 + * the database will be closed (after printing an error message on
\r
331 @@ -183,7 +206,7 @@ typedef struct _notmuch_filenames notmuch_filenames_t;
\r
332 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
\r
335 -notmuch_database_create (const char *path, notmuch_database_t **database);
\r
336 +notmuch_database_create (notmuch_database_t *notmuch, const char *path);
\r
339 NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
\r
340 @@ -201,11 +224,13 @@ typedef enum {
\r
341 * An existing notmuch database can be identified by the presence of a
\r
342 * directory named ".notmuch" below 'path'.
\r
344 - * The caller should call notmuch_database_destroy when finished with
\r
346 + * After a successful call to notmuch_database_open, the database will
\r
347 + * be open so the caller should call notmuch_database_close (or
\r
348 + * notmuch_database_destroy) when finished with the database.
\r
350 * In case of any failure, this function returns an error status and
\r
351 - * sets *database to NULL (after printing an error message on stderr).
\r
352 + * the database will be closed (after printing an error message on
\r
357 @@ -222,9 +247,8 @@ typedef enum {
\r
358 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
\r
361 -notmuch_database_open (const char *path,
\r
362 - notmuch_database_mode_t mode,
\r
363 - notmuch_database_t **database);
\r
364 +notmuch_database_open (notmuch_database_t *notmuch, const char *path,
\r
365 + notmuch_database_mode_t mode);
\r
367 /* Close the given notmuch database.
\r
369 @@ -264,7 +288,8 @@ typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure);
\r
370 * 'closure' is passed verbatim to any callback invoked.
\r
373 -notmuch_database_compact (const char* path,
\r
374 +notmuch_database_compact (notmuch_database_t *notmuch,
\r
375 + const char* path,
\r
376 const char* backup_path,
\r
377 notmuch_compact_status_cb_t status_cb,
\r
379 @@ -272,6 +297,9 @@ notmuch_database_compact (const char* path,
\r
380 /* Destroy the notmuch database, closing it if necessary and freeing
\r
381 * all associated resources.
\r
383 + * A database handle initialized with notmuch_database_new should be
\r
384 + * destroyed by calling notmuch_database_destroy.
\r
386 * Return value as in notmuch_database_close if the database was open;
\r
387 * notmuch_database_destroy itself has no failure modes.
\r
389 diff --git a/notmuch-compact.c b/notmuch-compact.c
\r
390 index 8b820c0..626685e 100644
\r
391 --- a/notmuch-compact.c
\r
392 +++ b/notmuch-compact.c
\r
393 @@ -29,6 +29,7 @@ status_update_cb (const char *msg, unused (void *closure))
\r
395 notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])
\r
397 + notmuch_database_t *notmuch = NULL;
\r
398 const char *path = notmuch_config_get_database_path (config);
\r
399 const char *backup_path = NULL;
\r
400 notmuch_status_t ret;
\r
401 @@ -46,7 +47,13 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])
\r
404 printf ("Compacting database...\n");
\r
405 - ret = notmuch_database_compact (path, backup_path,
\r
407 + if (notmuch_database_new (¬much)) {
\r
408 + fprintf (stderr, "Out of memory\n");
\r
412 + ret = notmuch_database_compact (notmuch, path, backup_path,
\r
413 quiet ? NULL : status_update_cb, NULL);
\r
415 fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string (ret));
\r
416 @@ -60,5 +67,7 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])
\r
417 printf ("Done.\n");
\r
420 + notmuch_database_destroy (notmuch);
\r
424 diff --git a/notmuch-count.c b/notmuch-count.c
\r
425 index 01e4e30..15c95c7 100644
\r
426 --- a/notmuch-count.c
\r
427 +++ b/notmuch-count.c
\r
428 @@ -170,8 +170,14 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
432 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
433 - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
434 + if (notmuch_database_new (¬much)) {
\r
435 + fprintf (stderr, "Out of memory\n");
\r
439 + if (notmuch_database_open (notmuch,
\r
440 + notmuch_config_get_database_path (config),
\r
441 + NOTMUCH_DATABASE_MODE_READ_ONLY))
\r
444 query_str = query_string_from_args (config, argc-opt_index, argv+opt_index);
\r
445 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
446 index 2024e30..73579bc 100644
\r
447 --- a/notmuch-dump.c
\r
448 +++ b/notmuch-dump.c
\r
449 @@ -33,8 +33,14 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
450 notmuch_tags_t *tags;
\r
451 const char *query_str = "";
\r
453 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
454 - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
455 + if (notmuch_database_new (¬much)) {
\r
456 + fprintf (stderr, "Out of memory\n");
\r
460 + if (notmuch_database_open (notmuch,
\r
461 + notmuch_config_get_database_path (config),
\r
462 + NOTMUCH_DATABASE_MODE_READ_ONLY))
\r
465 char *output_file_name = NULL;
\r
466 diff --git a/notmuch-insert.c b/notmuch-insert.c
\r
467 index 2207b1e..4a8aad3 100644
\r
468 --- a/notmuch-insert.c
\r
469 +++ b/notmuch-insert.c
\r
470 @@ -467,8 +467,14 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
471 action.sa_flags = 0;
\r
472 sigaction (SIGINT, &action, NULL);
\r
474 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
475 - NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
476 + if (notmuch_database_new (¬much)) {
\r
477 + fprintf (stderr, "Out of memory\n");
\r
481 + if (notmuch_database_open (notmuch,
\r
482 + notmuch_config_get_database_path (config),
\r
483 + NOTMUCH_DATABASE_MODE_READ_WRITE))
\r
486 ret = insert_message (config, notmuch, STDIN_FILENO, maildir, tag_ops);
\r
487 diff --git a/notmuch-new.c b/notmuch-new.c
\r
488 index ba05cb4..f72a4de 100644
\r
489 --- a/notmuch-new.c
\r
490 +++ b/notmuch-new.c
\r
491 @@ -914,6 +914,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
495 + if (notmuch_database_new (¬much)) {
\r
496 + fprintf (stderr, "Out of memory\n");
\r
500 dot_notmuch_path = talloc_asprintf (config, "%s/%s", db_path, ".notmuch");
\r
502 if (stat (dot_notmuch_path, &st)) {
\r
503 @@ -925,12 +930,12 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
506 printf ("Found %d total files (that's not much mail).\n", count);
\r
507 - if (notmuch_database_create (db_path, ¬much))
\r
508 + if (notmuch_database_create (notmuch, db_path))
\r
510 add_files_state.total_files = count;
\r
512 - if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,
\r
514 + if (notmuch_database_open (notmuch, db_path,
\r
515 + NOTMUCH_DATABASE_MODE_READ_WRITE))
\r
518 if (notmuch_database_needs_upgrade (notmuch)) {
\r
519 @@ -945,9 +950,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
520 add_files_state.total_files = 0;
\r
523 - if (notmuch == NULL)
\r
526 /* Setup our handler for SIGINT. We do this after having
\r
527 * potentially done a database upgrade we this interrupt handler
\r
528 * won't support. */
\r
529 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
530 index 9d6f843..7b80841 100644
\r
531 --- a/notmuch-reply.c
\r
532 +++ b/notmuch-reply.c
\r
533 @@ -769,8 +769,14 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
\r
537 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
538 - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
539 + if (notmuch_database_new (¬much)) {
\r
540 + fprintf (stderr, "Out of memory\n");
\r
544 + if (notmuch_database_open (notmuch,
\r
545 + notmuch_config_get_database_path (config),
\r
546 + NOTMUCH_DATABASE_MODE_READ_ONLY))
\r
549 query = notmuch_query_create (notmuch, query_string);
\r
550 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
551 index 1419621..fc37838 100644
\r
552 --- a/notmuch-restore.c
\r
553 +++ b/notmuch-restore.c
\r
554 @@ -138,8 +138,14 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
556 int input_format = DUMP_FORMAT_AUTO;
\r
558 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
559 - NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
560 + if (notmuch_database_new (¬much)) {
\r
561 + fprintf (stderr, "Out of memory\n");
\r
565 + if (notmuch_database_open (notmuch,
\r
566 + notmuch_config_get_database_path (config),
\r
567 + NOTMUCH_DATABASE_MODE_READ_WRITE))
\r
570 if (notmuch_config_get_maildir_synchronize_flags (config))
\r
571 diff --git a/notmuch-search.c b/notmuch-search.c
\r
572 index 7c973b3..50aace9 100644
\r
573 --- a/notmuch-search.c
\r
574 +++ b/notmuch-search.c
\r
575 @@ -430,8 +430,14 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
577 notmuch_exit_if_unsupported_format ();
\r
579 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
580 - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
581 + if (notmuch_database_new (¬much)) {
\r
582 + fprintf (stderr, "Out of memory\n");
\r
586 + if (notmuch_database_open (notmuch,
\r
587 + notmuch_config_get_database_path (config),
\r
588 + NOTMUCH_DATABASE_MODE_READ_ONLY))
\r
591 query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);
\r
592 diff --git a/notmuch-show.c b/notmuch-show.c
\r
593 index c07f887..bc44b2c 100644
\r
594 --- a/notmuch-show.c
\r
595 +++ b/notmuch-show.c
\r
596 @@ -1201,8 +1201,14 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
\r
600 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
601 - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
602 + if (notmuch_database_new (¬much)) {
\r
603 + fprintf (stderr, "Out of memory\n");
\r
607 + if (notmuch_database_open (notmuch,
\r
608 + notmuch_config_get_database_path (config),
\r
609 + NOTMUCH_DATABASE_MODE_READ_ONLY))
\r
612 query = notmuch_query_create (notmuch, query_string);
\r
613 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
614 index 3b09df9..6e29799 100644
\r
615 --- a/notmuch-tag.c
\r
616 +++ b/notmuch-tag.c
\r
617 @@ -254,8 +254,14 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
\r
621 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
622 - NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
623 + if (notmuch_database_new (¬much)) {
\r
624 + fprintf (stderr, "Out of memory\n");
\r
628 + if (notmuch_database_open (notmuch,
\r
629 + notmuch_config_get_database_path (config),
\r
630 + NOTMUCH_DATABASE_MODE_READ_WRITE))
\r
633 if (notmuch_config_get_maildir_synchronize_flags (config))
\r
634 diff --git a/test/random-corpus.c b/test/random-corpus.c
\r
635 index 790193d..2b205e5 100644
\r
636 --- a/test/random-corpus.c
\r
637 +++ b/test/random-corpus.c
\r
638 @@ -164,8 +164,14 @@ main (int argc, char **argv)
\r
639 if (config == NULL)
\r
642 - if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
643 - NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
644 + if (notmuch_database_new (¬much)) {
\r
645 + fprintf (stderr, "Out of memory\n");
\r
649 + if (notmuch_database_open (notmuch,
\r
650 + notmuch_config_get_database_path (config),
\r
651 + NOTMUCH_DATABASE_MODE_READ_WRITE))
\r
655 diff --git a/test/symbol-test.cc b/test/symbol-test.cc
\r
656 index 3e96c03..47c5351 100644
\r
657 --- a/test/symbol-test.cc
\r
658 +++ b/test/symbol-test.cc
\r
662 notmuch_database_t *notmuch;
\r
663 - notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much);
\r
664 + notmuch_database_new (¬much);
\r
665 + notmuch_database_open (notmuch, "fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
668 (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);
\r