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
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
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
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
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
64 From: Jani Nikula <jani@nikula.org>
\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
70 This is required for notmuch insert to report error status if message
\r
73 lib/database.cc | 30 ++++++++++++++++++++++++------
\r
74 lib/notmuch.h | 15 +++++++++++++--
\r
75 2 files changed, 37 insertions(+), 8 deletions(-)
\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
87 notmuch_database_close (notmuch_database_t *notmuch)
\r
89 + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
\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
102 notmuch->xapian_db->close();
\r
103 } catch (const Xapian::Error &error) {
\r
105 + /* don't clobber previous error status */
\r
106 + if (status == NOTMUCH_STATUS_SUCCESS)
\r
107 + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\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
119 #if HAVE_XAPIAN_COMPACT
\r
120 @@ -972,8 +979,15 @@ notmuch_database_compact (const char *path,
\r
125 - notmuch_database_destroy (notmuch);
\r
127 + notmuch_status_t ret2;
\r
129 + ret2 = notmuch_database_destroy (notmuch);
\r
131 + /* don't clobber previous error status */
\r
132 + if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS)
\r
136 talloc_free (local);
\r
138 @@ -991,11 +1005,15 @@ notmuch_database_compact (unused (const char *path),
\r
144 notmuch_database_destroy (notmuch_database_t *notmuch)
\r
146 - notmuch_database_close (notmuch);
\r
147 + notmuch_status_t status;
\r
149 + status = notmuch_database_close (notmuch);
\r
150 talloc_free (notmuch);
\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
162 * notmuch_database_close can be called multiple times. Later calls
\r
167 + * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.
\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
175 notmuch_database_close (notmuch_database_t *database);
\r
178 @@ -317,8 +325,11 @@ notmuch_database_compact (const char* path,
\r
180 * Destroy the notmuch database, closing it if necessary and freeing
\r
181 * all associated resources.
\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
188 notmuch_database_destroy (notmuch_database_t *database);
\r