Re: [PATCH] add has: query prefix to search for specific properties
[notmuch-archives.git] / 38 / 27af77704565f33229ca41a6c179f7262be8de
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 3DCA5431FC0\r
6         for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 09:21:02 -0800 (PST)\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 RW3jJQhRq-c9 for <notmuch@notmuchmail.org>;\r
16         Sun, 19 Jan 2014 09:20:53 -0800 (PST)\r
17 Received: from mail-ea0-f180.google.com (mail-ea0-f180.google.com\r
18         [209.85.215.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 24FE8431FBD\r
21         for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 09:20:53 -0800 (PST)\r
22 Received: by mail-ea0-f180.google.com with SMTP id f15so2654834eak.39\r
23         for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 09:20:50 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
27         bh=FM78c4W+E5Vv6uxqS07KLcar+lVzJdx9zl+rOiS8Okw=;\r
28         b=KZh6682lEtKeNiWJydd6PD4tGLSrEDvH3Stmp5zYzvi3uMFXtuqUYCHZSlEvt0JcgM\r
29         i5k9NeWp9YZLak4OBsCAt9OB5XOX0Bod3oi25cZYhHkBciIphQHGpKWfmU6w/hfKXwgv\r
30         ZRGLsTwtvSArla4G4S+kRkzGGuYCopf6AoY6AIM2xBy/31BqyD//qM+e3bPl/vhD3/Jt\r
31         Ckf6T+iQzmH9eIZsP2i6TQwZcMrUIpzJQRFs1421ooDbIB6PKR3FA0QBDbyR+6nVkc5/\r
32         Giu7Yhmf6pu/5BAuD14fSOenSOTuNc2Hl3xqRuwroBEy3fUtovf/u2pr6Zbb5YbrBaAB\r
33         z8pQ==\r
34 X-Gm-Message-State:\r
35  ALoCoQl0dfncpSZUdqwSLNHe6FqKkGS9lTPIYK+B6uOAnUAC+SNhRVsbs1NNQ5v4EvFNip7ZRYYc\r
36 X-Received: by 10.14.114.70 with SMTP id b46mr203478eeh.84.1390152049132;\r
37         Sun, 19 Jan 2014 09:20:49 -0800 (PST)\r
38 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
39         [88.195.111.91]) by mx.google.com with ESMTPSA id\r
40         o47sm45284052eem.21.2014.01.19.09.20.47 for <multiple recipients>\r
41         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
42         Sun, 19 Jan 2014 09:20:48 -0800 (PST)\r
43 From: Jani Nikula <jani@nikula.org>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH v2] lib: add return status to database close and destroy\r
46 Date: Sun, 19 Jan 2014 19:20:46 +0200\r
47 Message-Id: <1390152046-6509-1-git-send-email-jani@nikula.org>\r
48 X-Mailer: git-send-email 1.8.5.2\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sun, 19 Jan 2014 17:21:02 -0000\r
62 \r
63 notmuch_database_close may fail in Xapian ->flush() or ->close(), so\r
64 report the status. Similarly for notmuch_database_destroy which calls\r
65 close.\r
66 \r
67 This is required for notmuch insert to report error status if message\r
68 indexing failed.\r
69 \r
70 ---\r
71 \r
72 v2 of\r
73 id:29b808bb6bf051fe21b6a72f12bb4ad1badfbf97.1385903109.git.jani@nikula.org\r
74 picked out of the series.\r
75 ---\r
76  lib/database.cc | 30 ++++++++++++++++++++++++------\r
77  lib/notmuch.h   | 15 +++++++++++++--\r
78  2 files changed, 37 insertions(+), 8 deletions(-)\r
79 \r
80 diff --git a/lib/database.cc b/lib/database.cc\r
81 index f395061..46a9a8f 100644\r
82 --- a/lib/database.cc\r
83 +++ b/lib/database.cc\r
84 @@ -767,14 +767,17 @@ notmuch_database_open (const char *path,\r
85      return status;\r
86  }\r
87  \r
88 -void\r
89 +notmuch_status_t\r
90  notmuch_database_close (notmuch_database_t *notmuch)\r
91  {\r
92 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
93 +\r
94      try {\r
95         if (notmuch->xapian_db != NULL &&\r
96             notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
97             (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
98      } catch (const Xapian::Error &error) {\r
99 +       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
100         if (! notmuch->exception_reported) {\r
101             fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",\r
102                      error.get_msg().c_str());\r
103 @@ -788,7 +791,9 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
104         try {\r
105             notmuch->xapian_db->close();\r
106         } catch (const Xapian::Error &error) {\r
107 -           /* do nothing */\r
108 +           /* don't clobber previous error status */\r
109 +           if (status == NOTMUCH_STATUS_SUCCESS)\r
110 +               status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
111         }\r
112      }\r
113  \r
114 @@ -802,6 +807,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
115      notmuch->value_range_processor = NULL;\r
116      delete notmuch->date_range_processor;\r
117      notmuch->date_range_processor = NULL;\r
118 +\r
119 +    return status;\r
120  }\r
121  \r
122  #if HAVE_XAPIAN_COMPACT\r
123 @@ -965,8 +972,15 @@ notmuch_database_compact (const char *path,\r
124      }\r
125  \r
126    DONE:\r
127 -    if (notmuch)\r
128 -       notmuch_database_destroy (notmuch);\r
129 +    if (notmuch) {\r
130 +       notmuch_status_t ret2;\r
131 +\r
132 +       ret2 = notmuch_database_destroy (notmuch);\r
133 +\r
134 +       /* don't clobber previous error status */\r
135 +       if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS)\r
136 +           ret = ret2;\r
137 +    }\r
138  \r
139      talloc_free (local);\r
140  \r
141 @@ -984,11 +998,15 @@ notmuch_database_compact (unused (const char *path),\r
142  }\r
143  #endif\r
144  \r
145 -void\r
146 +notmuch_status_t\r
147  notmuch_database_destroy (notmuch_database_t *notmuch)\r
148  {\r
149 -    notmuch_database_close (notmuch);\r
150 +    notmuch_status_t status;\r
151 +\r
152 +    status = notmuch_database_close (notmuch);\r
153      talloc_free (notmuch);\r
154 +\r
155 +    return status;\r
156  }\r
157  \r
158  const char *\r
159 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
160 index 02604c5..7ac7118 100644\r
161 --- a/lib/notmuch.h\r
162 +++ b/lib/notmuch.h\r
163 @@ -287,8 +287,16 @@ notmuch_database_open (const char *path,\r
164   *\r
165   * notmuch_database_close can be called multiple times.  Later calls\r
166   * have no effect.\r
167 + *\r
168 + * Return value:\r
169 + *\r
170 + * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.\r
171 + *\r
172 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the\r
173 + *     database has been closed but there are no guarantees the\r
174 + *     changes to the database, if any, have been flushed to disk.\r
175   */\r
176 -void\r
177 +notmuch_status_t\r
178  notmuch_database_close (notmuch_database_t *database);\r
179  \r
180  /**\r
181 @@ -317,8 +325,11 @@ notmuch_database_compact (const char* path,\r
182  /**\r
183   * Destroy the notmuch database, closing it if necessary and freeing\r
184   * all associated resources.\r
185 + *\r
186 + * Return value as in notmuch_database_close if the database was open;\r
187 + * notmuch_database_destroy itself has no failure modes.\r
188   */\r
189 -void\r
190 +notmuch_status_t\r
191  notmuch_database_destroy (notmuch_database_t *database);\r
192  \r
193  /**\r
194 -- \r
195 1.8.5.2\r
196 \r