1 Return-Path: <prvs=567195f5a2=davidben@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 0ACA7431FD4
\r
6 for <notmuch@notmuchmail.org>; Tue, 23 Feb 2010 18:28:19 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.577 tagged_above=-999 required=5 tests=[AWL=1.022,
\r
12 BAYES_00=-2.599] 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 rZEcWSLUrQ0x for <notmuch@notmuchmail.org>;
\r
16 Tue, 23 Feb 2010 18:28:17 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 3B7AD431FAE
\r
20 for <notmuch@notmuchmail.org>; Tue, 23 Feb 2010 18:28:17 -0800 (PST)
\r
21 X-AuditID: 1209190e-b7ca7ae00000096e-91-4b848d9228a2
\r
22 Received: from mailhub-auth-2.mit.edu (MAILHUB-AUTH-2.MIT.EDU [18.7.62.36])
\r
23 by dmz-mailsec-scanner-3.mit.edu (Symantec Brightmail Gateway) with
\r
24 SMTP id B7.DF.02414.29D848B4; Tue, 23 Feb 2010 21:23:14 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id o1O2NE5o008874;
\r
27 Tue, 23 Feb 2010 21:23:14 -0500
\r
28 Received: from localhost.localdomain (ET-NINETY-THREE.MIT.EDU [18.208.1.93])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as davidben@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id o1O2NTit021532
\r
32 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT);
\r
33 Tue, 23 Feb 2010 21:23:34 -0500 (EST)
\r
34 From: David Benjamin <davidben@MIT.EDU>
\r
35 To: notmuch@notmuchmail.org
\r
36 Date: Tue, 23 Feb 2010 21:23:01 -0500
\r
37 Message-Id: <1266978183-19698-3-git-send-email-davidben@mit.edu>
\r
38 X-Mailer: git-send-email 1.7.0.18.g39b3
\r
39 In-Reply-To: <1266978183-19698-1-git-send-email-davidben@mit.edu>
\r
40 References: <1266978183-19698-1-git-send-email-davidben@mit.edu>
\r
41 X-Brightmail-Tracker: AAAAAA==
\r
42 Subject: [notmuch] [PATCH 2/4] Pass separate notmuch_path when opening
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Wed, 24 Feb 2010 02:28:19 -0000
\r
58 Avoid hard-coding $MAILSTORE/.notmuch in the database layer.
\r
60 Signed-off-by: David Benjamin <davidben@mit.edu>
\r
62 lib/database-private.h | 1 +
\r
63 lib/database.cc | 28 ++++++++++++++--------------
\r
64 lib/notmuch.h | 32 ++++++++++++++++++++------------
\r
65 notmuch-client.h | 4 ++++
\r
66 notmuch-config.c | 29 +++++++++++++++++++++++++++++
\r
67 notmuch-count.c | 4 ++--
\r
68 notmuch-dump.c | 4 ++--
\r
69 notmuch-new.c | 3 ++-
\r
70 notmuch-reply.c | 4 ++--
\r
71 notmuch-restore.c | 4 ++--
\r
72 notmuch-search-tags.c | 4 ++--
\r
73 notmuch-search.c | 4 ++--
\r
74 notmuch-show.c | 4 ++--
\r
75 notmuch-tag.c | 4 ++--
\r
76 14 files changed, 86 insertions(+), 43 deletions(-)
\r
78 diff --git a/lib/database-private.h b/lib/database-private.h
\r
79 index 41918d7..59ed117 100644
\r
80 --- a/lib/database-private.h
\r
81 +++ b/lib/database-private.h
\r
82 @@ -38,6 +38,7 @@ struct _notmuch_database {
\r
83 notmuch_bool_t exception_reported;
\r
86 + char *notmuch_path;
\r
88 notmuch_bool_t needs_upgrade;
\r
89 notmuch_database_mode_t mode;
\r
90 diff --git a/lib/database.cc b/lib/database.cc
\r
91 index 1bb24ec..f54fbd1 100644
\r
92 --- a/lib/database.cc
\r
93 +++ b/lib/database.cc
\r
94 @@ -437,14 +437,14 @@ parse_references (void *ctx,
\r
97 notmuch_database_t *
\r
98 -notmuch_database_create (const char *path)
\r
99 +notmuch_database_create (const char *path,
\r
100 + const char *notmuch_path)
\r
102 notmuch_database_t *notmuch = NULL;
\r
103 - char *notmuch_path = NULL;
\r
107 - if (path == NULL) {
\r
108 + if (path == NULL || notmuch_path == NULL) {
\r
109 fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
\r
112 @@ -462,8 +462,6 @@ notmuch_database_create (const char *path)
\r
116 - notmuch_path = talloc_asprintf (NULL, "%s/%s", path, ".notmuch");
\r
118 err = mkdir (notmuch_path, 0755);
\r
121 @@ -473,13 +471,11 @@ notmuch_database_create (const char *path)
\r
124 notmuch = notmuch_database_open (path,
\r
126 NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
127 notmuch_database_upgrade (notmuch, NULL, NULL);
\r
130 - if (notmuch_path)
\r
131 - talloc_free (notmuch_path);
\r
136 @@ -496,17 +492,17 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
\r
138 notmuch_database_t *
\r
139 notmuch_database_open (const char *path,
\r
140 + const char *notmuch_path,
\r
141 notmuch_database_mode_t mode)
\r
143 notmuch_database_t *notmuch = NULL;
\r
144 - char *notmuch_path = NULL, *xapian_path = NULL;
\r
145 + char *xapian_path = NULL;
\r
148 unsigned int i, version;
\r
150 - if (asprintf (¬much_path, "%s/%s", path, ".notmuch") == -1) {
\r
151 - notmuch_path = NULL;
\r
152 - fprintf (stderr, "Out of memory\n");
\r
153 + if (path == NULL || notmuch_path == NULL) {
\r
154 + fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
\r
158 @@ -611,8 +607,6 @@ notmuch_database_open (const char *path,
\r
162 - if (notmuch_path)
\r
163 - free (notmuch_path);
\r
165 free (xapian_path);
\r
167 @@ -645,6 +639,12 @@ notmuch_database_get_path (notmuch_database_t *notmuch)
\r
168 return notmuch->path;
\r
172 +notmuch_database_get_notmuch_path (notmuch_database_t *notmuch)
\r
174 + return notmuch->notmuch_path;
\r
178 notmuch_database_get_version (notmuch_database_t *notmuch)
\r
180 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
181 index d3e50a7..943c297 100644
\r
182 --- a/lib/notmuch.h
\r
183 +++ b/lib/notmuch.h
\r
184 @@ -120,12 +120,12 @@ typedef struct _notmuch_tags notmuch_tags_t;
\r
185 typedef struct _notmuch_directory notmuch_directory_t;
\r
186 typedef struct _notmuch_filenames notmuch_filenames_t;
\r
188 -/* Create a new, empty notmuch database located at 'path'.
\r
189 +/* Create a new, empty notmuch database located at 'notmuch_path',
\r
190 + * indexing mail store 'path'
\r
192 * The path should be a top-level directory to a collection of
\r
193 * plain-text email messages (one message per file). This call will
\r
194 - * create a new ".notmuch" directory within 'path' where notmuch will
\r
195 - * store its data.
\r
196 + * create directory 'notmuch_path' where notmuch will store its data.
\r
198 * After a successful call to notmuch_database_create, the returned
\r
199 * database will be open so the caller should call
\r
200 @@ -140,7 +140,8 @@ typedef struct _notmuch_filenames notmuch_filenames_t;
\r
201 * an error message on stderr).
\r
203 notmuch_database_t *
\r
204 -notmuch_database_create (const char *path);
\r
205 +notmuch_database_create (const char *path,
\r
206 + const char *notmuch_path);
\r
209 NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
\r
210 @@ -150,16 +151,15 @@ typedef enum {
\r
211 /* XXX: I think I'd like this to take an extra argument of
\r
212 * notmuch_status_t* for returning a status value on failure. */
\r
214 -/* Open an existing notmuch database located at 'path'.
\r
215 +/* Open an existing notmuch database located at 'notmuch_path' with
\r
216 + * mail store rooted at 'path'
\r
218 * The database should have been created at some time in the past,
\r
219 * (not necessarily by this process), by calling
\r
220 - * notmuch_database_create with 'path'. By default the database should be
\r
221 - * opened for reading only. In order to write to the database you need to
\r
222 - * pass the NOTMUCH_DATABASE_MODE_WRITABLE mode.
\r
224 - * An existing notmuch database can be identified by the presence of a
\r
225 - * directory named ".notmuch" below 'path'.
\r
226 + * notmuch_database_create with 'path' and 'notmuch_path'. By default
\r
227 + * the database should be opened for reading only. In order to write
\r
228 + * to the database you need to pass the NOTMUCH_DATABASE_MODE_WRITABLE
\r
231 * The caller should call notmuch_database_close when finished with
\r
233 @@ -169,6 +169,7 @@ typedef enum {
\r
235 notmuch_database_t *
\r
236 notmuch_database_open (const char *path,
\r
237 + const char *notmuch_path,
\r
238 notmuch_database_mode_t mode);
\r
240 /* Close the given notmuch database, freeing all associated
\r
241 @@ -176,13 +177,20 @@ notmuch_database_open (const char *path,
\r
243 notmuch_database_close (notmuch_database_t *database);
\r
245 -/* Return the database path of the given database.
\r
246 +/* Return the mail store path of the given database.
\r
248 * The return value is a string owned by notmuch so should not be
\r
249 * modified nor freed by the caller. */
\r
251 notmuch_database_get_path (notmuch_database_t *database);
\r
253 +/* Return the database path of the given database.
\r
255 + * The return value is a string owned by notmuch so should not be
\r
256 + * modified nor freed by the caller. */
\r
258 +notmuch_database_get_notmuch_path (notmuch_database_t *database);
\r
260 /* Return the database format version of the given database. */
\r
262 notmuch_database_get_version (notmuch_database_t *database);
\r
263 diff --git a/notmuch-client.h b/notmuch-client.h
\r
264 index c80b39c..1a676d2 100644
\r
265 --- a/notmuch-client.h
\r
266 +++ b/notmuch-client.h
\r
267 @@ -148,6 +148,10 @@ void
\r
268 notmuch_config_set_database_path (notmuch_config_t *config,
\r
269 const char *database_path);
\r
271 +notmuch_database_t *
\r
272 +notmuch_config_open_database (notmuch_config_t *config,
\r
273 + notmuch_database_mode_t mode);
\r
276 notmuch_config_get_user_name (notmuch_config_t *config);
\r
278 diff --git a/notmuch-config.c b/notmuch-config.c
\r
279 index 95430db..58a28b1 100644
\r
280 --- a/notmuch-config.c
\r
281 +++ b/notmuch-config.c
\r
282 @@ -353,6 +353,35 @@ notmuch_config_set_database_path (notmuch_config_t *config,
\r
283 config->database_path = NULL;
\r
286 +notmuch_database_t *
\r
287 +notmuch_config_open_database (notmuch_config_t *config,
\r
288 + notmuch_database_mode_t mode)
\r
290 + const char *path = NULL;
\r
291 + char *db_path = NULL;
\r
292 + notmuch_database_t *notmuch = NULL;
\r
294 + path = notmuch_config_get_database_path (config);
\r
295 + if (path == NULL) {
\r
296 + fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
\r
300 + if (asprintf (&db_path, "%s/%s", path, ".notmuch") == -1) {
\r
302 + fprintf (stderr, "Out of memory\n");
\r
306 + notmuch = notmuch_database_open (path, db_path, mode);
\r
316 notmuch_config_get_user_name (notmuch_config_t *config)
\r
318 diff --git a/notmuch-count.c b/notmuch-count.c
\r
319 index 77aa433..8d077eb 100644
\r
320 --- a/notmuch-count.c
\r
321 +++ b/notmuch-count.c
\r
322 @@ -80,8 +80,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
323 if (config == NULL)
\r
326 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
327 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
328 + notmuch = notmuch_config_open_database (config,
\r
329 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
330 if (notmuch == NULL)
\r
333 diff --git a/notmuch-dump.c b/notmuch-dump.c
\r
334 index ea326bb..a051fd4 100644
\r
335 --- a/notmuch-dump.c
\r
336 +++ b/notmuch-dump.c
\r
337 @@ -35,8 +35,8 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])
\r
338 if (config == NULL)
\r
341 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
342 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
343 + notmuch = notmuch_config_open_database (config,
\r
344 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
345 if (notmuch == NULL)
\r
348 diff --git a/notmuch-new.c b/notmuch-new.c
\r
349 index f25c71f..d24dab9 100644
\r
350 --- a/notmuch-new.c
\r
351 +++ b/notmuch-new.c
\r
352 @@ -749,10 +749,11 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
355 printf ("Found %d total files (that's not much mail).\n", count);
\r
356 - notmuch = notmuch_database_create (db_path);
\r
357 + notmuch = notmuch_database_create (db_path, dot_notmuch_path);
\r
358 add_files_state.total_files = count;
\r
360 notmuch = notmuch_database_open (db_path,
\r
361 + dot_notmuch_path,
\r
362 NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
363 if (notmuch == NULL)
\r
365 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
366 index 98f6442..10734bc 100644
\r
367 --- a/notmuch-reply.c
\r
368 +++ b/notmuch-reply.c
\r
369 @@ -467,8 +467,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
373 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
374 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
375 + notmuch = notmuch_config_open_database (config,
\r
376 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
377 if (notmuch == NULL)
\r
380 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
381 index 53ce254..d495b4f 100644
\r
382 --- a/notmuch-restore.c
\r
383 +++ b/notmuch-restore.c
\r
384 @@ -36,8 +36,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
385 if (config == NULL)
\r
388 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
389 - NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
390 + notmuch = notmuch_config_open_database (config,
\r
391 + NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
392 if (notmuch == NULL)
\r
395 diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c
\r
396 index 7a1305e..1ddbb94 100644
\r
397 --- a/notmuch-search-tags.c
\r
398 +++ b/notmuch-search-tags.c
\r
399 @@ -51,8 +51,8 @@ notmuch_search_tags_command (void *ctx, int argc, char *argv[])
\r
403 - db = notmuch_database_open (notmuch_config_get_database_path (config),
\r
404 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
405 + db = notmuch_config_open_database (config,
\r
406 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
410 diff --git a/notmuch-search.c b/notmuch-search.c
\r
411 index 25dd6eb..2b65e87 100644
\r
412 --- a/notmuch-search.c
\r
413 +++ b/notmuch-search.c
\r
414 @@ -244,8 +244,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
415 if (config == NULL)
\r
418 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
419 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
420 + notmuch = notmuch_config_open_database (config,
\r
421 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
422 if (notmuch == NULL)
\r
425 diff --git a/notmuch-show.c b/notmuch-show.c
\r
426 index 1a1d601..88124dc 100644
\r
427 --- a/notmuch-show.c
\r
428 +++ b/notmuch-show.c
\r
429 @@ -446,8 +446,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
433 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
434 - NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
435 + notmuch = notmuch_config_open_database (config,
\r
436 + NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
437 if (notmuch == NULL)
\r
440 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
441 index 00588a1..1deff1a 100644
\r
442 --- a/notmuch-tag.c
\r
443 +++ b/notmuch-tag.c
\r
444 @@ -96,8 +96,8 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
445 if (config == NULL)
\r
448 - notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
449 - NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
450 + notmuch = notmuch_config_open_database (config,
\r
451 + NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
452 if (notmuch == NULL)
\r