Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / c6 / bb455792135b8d4efdfd79a5a31cb3ab6234c5
1 Return-Path: <novalazy@gmail.com>\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 1C5AC431FAE\r
6         for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 05:59:53 -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.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, 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 lxzgLNUZ5nxx for <notmuch@notmuchmail.org>;\r
17         Wed, 16 Apr 2014 05:59:45 -0700 (PDT)\r
18 Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com\r
19         [209.85.160.48]) (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 B9393431FBD\r
22         for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 05:59:45 -0700 (PDT)\r
23 Received: by mail-pb0-f48.google.com with SMTP id md12so10811001pbc.21\r
24         for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 05:59:44 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
27         bh=sLA/eo+oalwo7mq/wx2zV958LJUsx3y51c3R8q57lOM=;\r
28         b=cczvDjyy/eSuq7dxhPSnzGtgfueFEYeUFb8TmzfkPPgw9hEO/p3cGZBQ/bhZfYOHzW\r
29         RTkj3CH55BdAaM1bU+3qbdB5VI516e3y+z72U7xuWpYl3hh+dLIQib/U0ClF7xCRt6Dc\r
30         NmugiUAZrnRW8v2/6mMLsbMCipA4j5xZvh++rpu4PQUfHoOhTDE51tNpTOlmMO0iaYmI\r
31         pwHPPfkmRspvTxXYpTb+80Uwu4LjSUzhgNEh6h6r/BZKJ97iltJoNzcH5Nb/U3cQFj3u\r
32         hI8KmID/UNJOoD/icBFBlDKftxzAn4nDL0/imMDmsnraU0ABZcUMqBgP2laIfPaexeXj\r
33         rjXQ==\r
34 X-Received: by 10.68.221.42 with SMTP id qb10mr8324273pbc.65.1397653183958;\r
35         Wed, 16 Apr 2014 05:59:43 -0700 (PDT)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPSA id ja8sm46975039pbd.3.2014.04.16.05.59.41\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
41         Wed, 16 Apr 2014 05:59:43 -0700 (PDT)\r
42 From: Peter Wang <novalazy@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v2 01/10] lib: add return status to database close and destroy\r
45 Date: Wed, 16 Apr 2014 22:59:16 +1000\r
46 Message-Id: <1397653165-15620-2-git-send-email-novalazy@gmail.com>\r
47 X-Mailer: git-send-email 1.8.4\r
48 In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com>\r
49 References: <1397653165-15620-1-git-send-email-novalazy@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Wed, 16 Apr 2014 12:59:53 -0000\r
63 \r
64 From: Jani Nikula <jani@nikula.org>\r
65 \r
66 notmuch_database_close may fail in Xapian ->flush() or ->close(), so\r
67 report the status. Similarly for notmuch_database_destroy which calls\r
68 close.\r
69 \r
70 This is required for notmuch insert to report error status if message\r
71 indexing failed.\r
72 ---\r
73  lib/database.cc | 30 ++++++++++++++++++++++++------\r
74  lib/notmuch.h   | 15 +++++++++++++--\r
75  2 files changed, 37 insertions(+), 8 deletions(-)\r
76 \r
77 diff --git a/lib/database.cc b/lib/database.cc\r
78 index 1efb14d..ef7005b 100644\r
79 --- a/lib/database.cc\r
80 +++ b/lib/database.cc\r
81 @@ -774,14 +774,17 @@ notmuch_database_open (const char *path,\r
82      return status;\r
83  }\r
84  \r
85 -void\r
86 +notmuch_status_t\r
87  notmuch_database_close (notmuch_database_t *notmuch)\r
88  {\r
89 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
90 +\r
91      try {\r
92         if (notmuch->xapian_db != NULL &&\r
93             notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
94             (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
95      } catch (const Xapian::Error &error) {\r
96 +       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
97         if (! notmuch->exception_reported) {\r
98             fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",\r
99                      error.get_msg().c_str());\r
100 @@ -795,7 +798,9 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
101         try {\r
102             notmuch->xapian_db->close();\r
103         } catch (const Xapian::Error &error) {\r
104 -           /* do nothing */\r
105 +           /* don't clobber previous error status */\r
106 +           if (status == NOTMUCH_STATUS_SUCCESS)\r
107 +               status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
108         }\r
109      }\r
110  \r
111 @@ -809,6 +814,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
112      notmuch->value_range_processor = NULL;\r
113      delete notmuch->date_range_processor;\r
114      notmuch->date_range_processor = NULL;\r
115 +\r
116 +    return status;\r
117  }\r
118  \r
119  #if HAVE_XAPIAN_COMPACT\r
120 @@ -972,8 +979,15 @@ notmuch_database_compact (const char *path,\r
121      }\r
122  \r
123    DONE:\r
124 -    if (notmuch)\r
125 -       notmuch_database_destroy (notmuch);\r
126 +    if (notmuch) {\r
127 +       notmuch_status_t ret2;\r
128 +\r
129 +       ret2 = notmuch_database_destroy (notmuch);\r
130 +\r
131 +       /* don't clobber previous error status */\r
132 +       if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS)\r
133 +           ret = ret2;\r
134 +    }\r
135  \r
136      talloc_free (local);\r
137  \r
138 @@ -991,11 +1005,15 @@ notmuch_database_compact (unused (const char *path),\r
139  }\r
140  #endif\r
141  \r
142 -void\r
143 +notmuch_status_t\r
144  notmuch_database_destroy (notmuch_database_t *notmuch)\r
145  {\r
146 -    notmuch_database_close (notmuch);\r
147 +    notmuch_status_t status;\r
148 +\r
149 +    status = notmuch_database_close (notmuch);\r
150      talloc_free (notmuch);\r
151 +\r
152 +    return status;\r
153  }\r
154  \r
155  const char *\r
156 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
157 index 350bed8..3c5ec98 100644\r
158 --- a/lib/notmuch.h\r
159 +++ b/lib/notmuch.h\r
160 @@ -287,8 +287,16 @@ notmuch_database_open (const char *path,\r
161   *\r
162   * notmuch_database_close can be called multiple times.  Later calls\r
163   * have no effect.\r
164 + *\r
165 + * Return value:\r
166 + *\r
167 + * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.\r
168 + *\r
169 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the\r
170 + *     database has been closed but there are no guarantees the\r
171 + *     changes to the database, if any, have been flushed to disk.\r
172   */\r
173 -void\r
174 +notmuch_status_t\r
175  notmuch_database_close (notmuch_database_t *database);\r
176  \r
177  /**\r
178 @@ -317,8 +325,11 @@ notmuch_database_compact (const char* path,\r
179  /**\r
180   * Destroy the notmuch database, closing it if necessary and freeing\r
181   * all associated resources.\r
182 + *\r
183 + * Return value as in notmuch_database_close if the database was open;\r
184 + * notmuch_database_destroy itself has no failure modes.\r
185   */\r
186 -void\r
187 +notmuch_status_t\r
188  notmuch_database_destroy (notmuch_database_t *database);\r
189  \r
190  /**\r
191 -- \r
192 1.8.4\r
193 \r