Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / a5 / f030d1a4b7ea33a4f73f3059afcdbbb0e9520d
1 Return-Path: <amthrax@drake.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 DA802431FB6\r
6         for <notmuch@notmuchmail.org>; Sat, 28 Apr 2012 15:18:03 -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: -0.7\r
10 X-Spam-Level: \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 JLiq5t7m1cK9 for <notmuch@notmuchmail.org>;\r
16         Sat, 28 Apr 2012 15:18:01 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
18         [18.9.25.12])\r
19         by olra.theworths.org (Postfix) with ESMTP id 008FD431FC2\r
20         for <notmuch@notmuchmail.org>; Sat, 28 Apr 2012 15:17:59 -0700 (PDT)\r
21 X-AuditID: 1209190c-b7fad6d000000920-ae-4f9c6c97ab96\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 20.19.02336.79C6C9F4; Sat, 28 Apr 2012 18:17:59 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q3SMHwFx005266; \r
27         Sat, 28 Apr 2012 18:17:58 -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 q3SMHvfi008918\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sat, 28 Apr 2012 18:17:58 -0400 (EDT)\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
36         (envelope-from <amthrax@drake.mit.edu>)\r
37         id 1SOFxk-00058D-UF; Sat, 28 Apr 2012 18:17:57 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 1/6] lib/cli: Make notmuch_database_open return a status code\r
41 Date: Sat, 28 Apr 2012 18:17:48 -0400\r
42 Message-Id: <1335651473-19652-2-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.9.1\r
44 In-Reply-To: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
45 References: <1335651473-19652-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrTs9Z46/wbwGRYvrN2cyOzB6PFt1\r
48         izmAMYrLJiU1J7MstUjfLoEro+uvT8E974rD+w6xNTAutuli5OSQEDCReHj6CDOELSZx4d56\r
49         ti5GLg4hgX2MEvvb37JDOBsYJe6v/Abl3GeS6N2+kxGkRUhgPqPE3gfuIDabgIbEtv3LweIi\r
50         AtISO+/OZu1i5OBgFlCT+NOlAhIWFvCV6L/dwwpiswioSjRdX88CYvMKOEjs7rrPCnGFgsSz\r
51         dceZQGxOAUeJ/5tPsEOscpDomDeBbQIj/wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6hnq5\r
52         mSV6qSmlmxjBISPJs4PxzUGlQ4wCHIxKPLwH18/yF2JNLCuuzD3EKMnBpCTKy5I1x1+ILyk/\r
53         pTIjsTgjvqg0J7X4EKMEB7OSCK+2OFCONyWxsiq1KB8mJc3BoiTOq6L1zk9IID2xJDU7NbUg\r
54         tQgmK8PBoSTB25oN1ChYlJqeWpGWmVOCkGbi4AQZzgM0fA9IDW9xQWJucWY6RP4Uo6KUOO96\r
55         kIQASCKjNA+uFxbTrxjFgV4R5p0OUsUDTAdw3a+ABjMBDWbynAUyuCQRISXVwDjhWIxX4R/T\r
56         fPUDRdyXtfv3/ZeuT1ffU1+0nPeKsPXsmsNftnVGHFn0VeAxf8Td+Yu/xPNY9Srv51byXjnd\r
57         9OLbouS92xsC+lbcUVi++/8M9Z+X3/zJ6YkIOGS9US7DK1FLRCVkoxy7qGJA2dIPprZJGbfX\r
58         1alsXMKqu6dW6m+CaHyFRNkWaSWW4oxEQy3mouJEADajNlLEAgAA\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Sat, 28 Apr 2012 22:18:04 -0000\r
72 \r
73 It has been a long-standing issue that notmuch_database_open doesn't\r
74 return any indication of why it failed.  This patch changes its\r
75 prototype to return a notmuch_status_t and set an out-argument to the\r
76 database itself, like other functions that return both a status and an\r
77 object.\r
78 \r
79 In the interest of atomicity, this also updates every use in the CLI\r
80 so that notmuch still compiles.  Since this patch does not update the\r
81 bindings, the Python bindings test fails.\r
82 ---\r
83  lib/database.cc     |   19 ++++++++++++++-----\r
84  lib/notmuch.h       |   12 +++++-------\r
85  notmuch-count.c     |    5 ++---\r
86  notmuch-dump.c      |    5 ++---\r
87  notmuch-new.c       |    5 ++---\r
88  notmuch-reply.c     |    5 ++---\r
89  notmuch-restore.c   |    5 ++---\r
90  notmuch-search.c    |    5 ++---\r
91  notmuch-show.c      |    5 ++---\r
92  notmuch-tag.c       |    5 ++---\r
93  test/symbol-test.cc |    3 ++-\r
94  11 files changed, 37 insertions(+), 37 deletions(-)\r
95 \r
96 diff --git a/lib/database.cc b/lib/database.cc\r
97 index 2fefcad..a29fe67 100644\r
98 --- a/lib/database.cc\r
99 +++ b/lib/database.cc\r
100 @@ -556,8 +556,9 @@ notmuch_database_create (const char *path)\r
101         goto DONE;\r
102      }\r
103  \r
104 -    notmuch = notmuch_database_open (path,\r
105 -                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
106 +    notmuch_database_open (path,\r
107 +                          NOTMUCH_DATABASE_MODE_READ_WRITE,\r
108 +                          &notmuch);\r
109      notmuch_database_upgrade (notmuch, NULL, NULL);\r
110  \r
111    DONE:\r
112 @@ -578,10 +579,12 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
113      return NOTMUCH_STATUS_SUCCESS;\r
114  }\r
115  \r
116 -notmuch_database_t *\r
117 +notmuch_status_t\r
118  notmuch_database_open (const char *path,\r
119 -                      notmuch_database_mode_t mode)\r
120 +                      notmuch_database_mode_t mode,\r
121 +                      notmuch_database_t **database)\r
122  {\r
123 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
124      void *local = talloc_new (NULL);\r
125      notmuch_database_t *notmuch = NULL;\r
126      char *notmuch_path, *xapian_path;\r
127 @@ -592,6 +595,7 @@ notmuch_database_open (const char *path,\r
128  \r
129      if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {\r
130         fprintf (stderr, "Out of memory\n");\r
131 +       status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
132         goto DONE;\r
133      }\r
134  \r
135 @@ -599,11 +603,13 @@ notmuch_database_open (const char *path,\r
136      if (err) {\r
137         fprintf (stderr, "Error opening database at %s: %s\n",\r
138                  notmuch_path, strerror (errno));\r
139 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
140         goto DONE;\r
141      }\r
142  \r
143      if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
144         fprintf (stderr, "Out of memory\n");\r
145 +       status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
146         goto DONE;\r
147      }\r
148  \r
149 @@ -644,6 +650,7 @@ notmuch_database_open (const char *path,\r
150                 notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
151                 notmuch_database_destroy (notmuch);\r
152                 notmuch = NULL;\r
153 +               status = NOTMUCH_STATUS_FILE_ERROR;\r
154                 goto DONE;\r
155             }\r
156  \r
157 @@ -704,12 +711,14 @@ notmuch_database_open (const char *path,\r
158                  error.get_msg().c_str());\r
159         notmuch_database_destroy (notmuch);\r
160         notmuch = NULL;\r
161 +       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
162      }\r
163  \r
164    DONE:\r
165      talloc_free (local);\r
166  \r
167 -    return notmuch;\r
168 +    *database = notmuch;\r
169 +    return status;\r
170  }\r
171  \r
172  void\r
173 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
174 index 7d9e092..8a011f2 100644\r
175 --- a/lib/notmuch.h\r
176 +++ b/lib/notmuch.h\r
177 @@ -151,9 +151,6 @@ typedef enum {\r
178      NOTMUCH_DATABASE_MODE_READ_WRITE\r
179  } notmuch_database_mode_t;\r
180  \r
181 -/* XXX: I think I'd like this to take an extra argument of\r
182 - * notmuch_status_t* for returning a status value on failure. */\r
183 -\r
184  /* Open an existing notmuch database located at 'path'.\r
185   *\r
186   * The database should have been created at some time in the past,\r
187 @@ -168,12 +165,13 @@ typedef enum {\r
188   * The caller should call notmuch_database_destroy when finished with\r
189   * this database.\r
190   *\r
191 - * In case of any failure, this function returns NULL, (after printing\r
192 - * an error message on stderr).\r
193 + * In case of any failure, this function returns an error status and\r
194 + * sets *database to NULL (after printing an error message on stderr).\r
195   */\r
196 -notmuch_database_t *\r
197 +notmuch_status_t\r
198  notmuch_database_open (const char *path,\r
199 -                      notmuch_database_mode_t mode);\r
200 +                      notmuch_database_mode_t mode,\r
201 +                      notmuch_database_t **database);\r
202  \r
203  /* Close the given notmuch database.\r
204   *\r
205 diff --git a/notmuch-count.c b/notmuch-count.c\r
206 index 9c2ad7b..2f98128 100644\r
207 --- a/notmuch-count.c\r
208 +++ b/notmuch-count.c\r
209 @@ -66,9 +66,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
210      if (config == NULL)\r
211         return 1;\r
212  \r
213 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
214 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
215 -    if (notmuch == NULL)\r
216 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
217 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
218         return 1;\r
219  \r
220      query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
221 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
222 index 71ab0ea..3743214 100644\r
223 --- a/notmuch-dump.c\r
224 +++ b/notmuch-dump.c\r
225 @@ -36,9 +36,8 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
226      if (config == NULL)\r
227         return 1;\r
228  \r
229 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
230 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
231 -    if (notmuch == NULL)\r
232 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
233 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
234         return 1;\r
235  \r
236      char *output_file_name = NULL;\r
237 diff --git a/notmuch-new.c b/notmuch-new.c\r
238 index 3ff6304..7788743 100644\r
239 --- a/notmuch-new.c\r
240 +++ b/notmuch-new.c\r
241 @@ -903,9 +903,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
242         notmuch = notmuch_database_create (db_path);\r
243         add_files_state.total_files = count;\r
244      } else {\r
245 -       notmuch = notmuch_database_open (db_path,\r
246 -                                        NOTMUCH_DATABASE_MODE_READ_WRITE);\r
247 -       if (notmuch == NULL)\r
248 +       if (notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE,\r
249 +                                  &notmuch))\r
250             return 1;\r
251  \r
252         if (notmuch_database_needs_upgrade (notmuch)) {\r
253 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
254 index da99a13..7184a5d 100644\r
255 --- a/notmuch-reply.c\r
256 +++ b/notmuch-reply.c\r
257 @@ -740,9 +740,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
258         return 1;\r
259      }\r
260  \r
261 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
262 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
263 -    if (notmuch == NULL)\r
264 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
265 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
266         return 1;\r
267  \r
268      query = notmuch_query_create (notmuch, query_string);\r
269 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
270 index 02b563c..4f4096e 100644\r
271 --- a/notmuch-restore.c\r
272 +++ b/notmuch-restore.c\r
273 @@ -115,9 +115,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
274      if (config == NULL)\r
275         return 1;\r
276  \r
277 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
278 -                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
279 -    if (notmuch == NULL)\r
280 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
281 +                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
282         return 1;\r
283  \r
284      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
285 diff --git a/notmuch-search.c b/notmuch-search.c\r
286 index 7dfd270..3be296d 100644\r
287 --- a/notmuch-search.c\r
288 +++ b/notmuch-search.c\r
289 @@ -486,9 +486,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
290      if (config == NULL)\r
291         return 1;\r
292  \r
293 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
294 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
295 -    if (notmuch == NULL)\r
296 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
297 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
298         return 1;\r
299  \r
300      query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);\r
301 diff --git a/notmuch-show.c b/notmuch-show.c\r
302 index 3b6667c..95427d4 100644\r
303 --- a/notmuch-show.c\r
304 +++ b/notmuch-show.c\r
305 @@ -1081,9 +1081,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
306         return 1;\r
307      }\r
308  \r
309 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
310 -                                    NOTMUCH_DATABASE_MODE_READ_ONLY);\r
311 -    if (notmuch == NULL)\r
312 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
313 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
314         return 1;\r
315  \r
316      query = notmuch_query_create (notmuch, query_string);\r
317 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
318 index bd56fd1..7d18639 100644\r
319 --- a/notmuch-tag.c\r
320 +++ b/notmuch-tag.c\r
321 @@ -229,9 +229,8 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
322      if (config == NULL)\r
323         return 1;\r
324  \r
325 -    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
326 -                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
327 -    if (notmuch == NULL)\r
328 +    if (notmuch_database_open (notmuch_config_get_database_path (config),\r
329 +                              NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
330         return 1;\r
331  \r
332      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
333 diff --git a/test/symbol-test.cc b/test/symbol-test.cc\r
334 index 1548ca4..3e96c03 100644\r
335 --- a/test/symbol-test.cc\r
336 +++ b/test/symbol-test.cc\r
337 @@ -4,7 +4,8 @@\r
338  \r
339  \r
340  int main() {\r
341 -  (void) notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY);\r
342 +  notmuch_database_t *notmuch;\r
343 +  notmuch_database_open("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch);\r
344  \r
345    try {\r
346      (void) new Xapian::WritableDatabase("./nonexistant", Xapian::DB_OPEN);\r
347 -- \r
348 1.7.9.1\r
349 \r