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 E435A429E38
\r
6 for <notmuch@notmuchmail.org>; Thu, 17 May 2012 21:13:57 -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 5QKL3f7IKhu0 for <notmuch@notmuchmail.org>;
\r
16 Thu, 17 May 2012 21:13:55 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 367DB431FDB
\r
20 for <notmuch@notmuchmail.org>; Thu, 17 May 2012 21:13:53 -0700 (PDT)
\r
21 X-AuditID: 12074424-b7fae6d000000906-f7-4fb5cc809d4b
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 64.51.02310.08CC5BF4; Fri, 18 May 2012 00:13:52 -0400 (EDT)
\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 q4I4Dpb8021449;
\r
27 Fri, 18 May 2012 00:13:51 -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 q4I4Dn14026781
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Fri, 18 May 2012 00:13:51 -0400 (EDT)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
36 (envelope-from <amdragon@mit.edu>)
\r
37 id 1SVEZZ-0000yx-OQ; Fri, 18 May 2012 00:13:49 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 1/9] lib: Make directory document creation optional for
\r
41 _notmuch_directory_create
\r
42 Date: Fri, 18 May 2012 00:13:34 -0400
\r
43 Message-Id: <1337314423-3702-2-git-send-email-amdragon@mit.edu>
\r
44 X-Mailer: git-send-email 1.7.10
\r
45 In-Reply-To: <1337314423-3702-1-git-send-email-amdragon@mit.edu>
\r
46 References: <1337314423-3702-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixG6nottwZqu/wYSDohbXb85kdmD0eLbq
\r
49 FnMAYxSXTUpqTmZZapG+XQJXxrQZy9kLbutV/Hx2hLWB8YRqFyMnh4SAicSrmR9YIGwxiQv3
\r
50 1rN1MXJxCAnsY5S4+f0GK4SzgVHiyZ0FYFVCAveZJOZMyYBIzGKU+HXkOyNIgk1AQ2Lb/uVg
\r
51 toiAtMTOu7OBujk4mAXUJP50qYCYwgKJEktfxYBUsAioSsyc/JUVxOYVsJe40LyHFeIIeYmn
\r
52 9/vYQMo5BRwkph2PhthqL/HvQjPLBEb+BYwMqxhlU3KrdHMTM3OKU5N1i5MT8/JSi3TN9XIz
\r
53 S/RSU0o3MYIDxkVlB2PzIaVDjAIcjEo8vALzt/oLsSaWFVfmHmKU5GBSEuX9fhIoxJeUn1KZ
\r
54 kVicEV9UmpNafIhRgoNZSYRXthsox5uSWFmVWpQPk5LmYFES59XQeucnJJCeWJKanZpakFoE
\r
55 k5Xh4FCS4N10GqhRsCg1PbUiLTOnBCHNxMEJMpwHaHgmSA1vcUFibnFmOkT+FKOilDhvGUhC
\r
56 ACSRUZoH1wuL6FeM4kCvCPNOAKniASYDuO5XQIOZgAaX5W4CGVySiJCSamA8cOzpK9bQpLsM
\r
57 7h8/S30L3fPyinThIv3aU+ynq8znrA8VFNXXznEu2KjsMuE/g9tZ3Z26Coe6c2K3dy06G10a
\r
58 OpXjVtG6/+r2Ajvufnsak9TnZ+nmlyYT1WjxzLat7Ztz9O+6bzub7P48PNIT3nfv7JNdIjkz
\r
59 CwsOMG89/P+D6YuNbUV+Hy8qsRRnJBpqMRcVJwIAiYfN1cMCAAA=
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Fri, 18 May 2012 04:13:58 -0000
\r
74 Previously this function would create directory documents if they
\r
75 didn't exist. As a result, it could only be used on writable
\r
76 databases. This adds an argument to make creation optional and to
\r
77 make this function work on read-only databases. We use a flag
\r
78 argument to avoid a bare boolean and to permit future expansion.
\r
80 Both callers have been updated, but currently retain the old behavior.
\r
81 We'll take advantage of the new argument in the following patches.
\r
83 lib/database.cc | 6 +++---
\r
84 lib/directory.cc | 33 ++++++++++++++++++++++++++++-----
\r
85 lib/notmuch-private.h | 8 ++++++++
\r
86 3 files changed, 39 insertions(+), 8 deletions(-)
\r
88 diff --git a/lib/database.cc b/lib/database.cc
\r
89 index f8c4a7d..df996a9 100644
\r
90 --- a/lib/database.cc
\r
91 +++ b/lib/database.cc
\r
92 @@ -956,7 +956,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
93 document.get_value (NOTMUCH_VALUE_TIMESTAMP));
\r
95 directory = _notmuch_directory_create (notmuch, term.c_str() + 10,
\r
97 + NOTMUCH_FIND_CREATE, &status);
\r
98 notmuch_directory_set_mtime (directory, mtime);
\r
99 notmuch_directory_destroy (directory);
\r
101 @@ -1210,7 +1210,7 @@ _notmuch_database_find_directory_id (notmuch_database_t *notmuch,
\r
102 return NOTMUCH_STATUS_SUCCESS;
\r
105 - directory = _notmuch_directory_create (notmuch, path, &status);
\r
106 + directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status);
\r
108 *directory_id = -1;
\r
110 @@ -1320,7 +1320,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,
\r
111 return NOTMUCH_STATUS_READ_ONLY_DATABASE;
\r
114 - *directory = _notmuch_directory_create (notmuch, path, &status);
\r
115 + *directory = _notmuch_directory_create (notmuch, path, NOTMUCH_FIND_CREATE, &status);
\r
116 } catch (const Xapian::Error &error) {
\r
117 fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
\r
118 error.get_msg().c_str());
\r
119 diff --git a/lib/directory.cc b/lib/directory.cc
\r
120 index 70e1693..83bb19b 100644
\r
121 --- a/lib/directory.cc
\r
122 +++ b/lib/directory.cc
\r
123 @@ -82,28 +82,41 @@ find_directory_document (notmuch_database_t *notmuch,
\r
124 return NOTMUCH_PRIVATE_STATUS_SUCCESS;
\r
127 +/* Find or create a directory document.
\r
129 + * 'path' should be a path relative to the path of 'database', or else
\r
130 + * should be an absolute path with initial components that match the
\r
131 + * path of 'database'.
\r
133 + * If (flags & NOTMUCH_FIND_CREATE), then the directory document will
\r
134 + * be created if it does not exist. Otherwise, if the directory
\r
135 + * document does not exist, *status_ret is set to
\r
136 + * NOTMUCH_STATUS_SUCCESS and this returns NULL.
\r
138 notmuch_directory_t *
\r
139 _notmuch_directory_create (notmuch_database_t *notmuch,
\r
141 + notmuch_find_flags_t flags,
\r
142 notmuch_status_t *status_ret)
\r
144 Xapian::WritableDatabase *db;
\r
145 notmuch_directory_t *directory;
\r
146 notmuch_private_status_t private_status;
\r
147 const char *db_path;
\r
148 + notmuch_bool_t create = (flags & NOTMUCH_FIND_CREATE);
\r
150 *status_ret = NOTMUCH_STATUS_SUCCESS;
\r
152 path = _notmuch_database_relative_path (notmuch, path);
\r
154 - if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
\r
155 + if (create && notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
\r
156 INTERNAL_ERROR ("Failure to ensure database is writable");
\r
158 - db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
160 directory = talloc (notmuch, notmuch_directory_t);
\r
161 - if (unlikely (directory == NULL))
\r
162 + if (unlikely (directory == NULL)) {
\r
163 + *status_ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
167 directory->notmuch = notmuch;
\r
169 @@ -122,6 +135,13 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
\r
170 directory->document_id = directory->doc.get_docid ();
\r
172 if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
174 + notmuch_directory_destroy (directory);
\r
175 + directory = NULL;
\r
176 + *status_ret = NOTMUCH_STATUS_SUCCESS;
\r
180 void *local = talloc_new (directory);
\r
181 const char *parent, *basename;
\r
182 Xapian::docid parent_id;
\r
183 @@ -145,6 +165,8 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
\r
184 directory->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
\r
185 Xapian::sortable_serialise (0));
\r
187 + db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
189 directory->document_id = _notmuch_database_generate_doc_id (notmuch);
\r
190 db->replace_document (directory->document_id, directory->doc);
\r
191 talloc_free (local);
\r
192 @@ -158,10 +180,11 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
\r
193 error.get_msg().c_str());
\r
194 notmuch->exception_reported = TRUE;
\r
195 notmuch_directory_destroy (directory);
\r
196 + directory = NULL;
\r
197 *status_ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
202 if (db_path != path)
\r
203 free ((char *) db_path);
\r
205 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
206 index 3886e0c..538274f 100644
\r
207 --- a/lib/notmuch-private.h
\r
208 +++ b/lib/notmuch-private.h
\r
209 @@ -146,6 +146,13 @@ typedef enum _notmuch_private_status {
\r
211 (notmuch_status_t) private_status)
\r
213 +/* Flags shared by various lookup functions. */
\r
214 +typedef enum _notmuch_find_flags {
\r
215 + /* If set, create the necessary document (or documents) if they
\r
216 + * are missing. Requires a read/write database. */
\r
217 + NOTMUCH_FIND_CREATE = 1<<0,
\r
218 +} notmuch_find_flags_t;
\r
220 typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
\r
222 typedef struct _notmuch_string_list notmuch_string_list_t;
\r
223 @@ -206,6 +213,7 @@ _notmuch_database_filename_to_direntry (void *ctx,
\r
224 notmuch_directory_t *
\r
225 _notmuch_directory_create (notmuch_database_t *notmuch,
\r
227 + notmuch_find_flags_t flags,
\r
228 notmuch_status_t *status_ret);
\r