--- /dev/null
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1C5AC431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 05:59:53 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id lxzgLNUZ5nxx for <notmuch@notmuchmail.org>;\r
+ Wed, 16 Apr 2014 05:59:45 -0700 (PDT)\r
+Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com\r
+ [209.85.160.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id B9393431FBD\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 05:59:45 -0700 (PDT)\r
+Received: by mail-pb0-f48.google.com with SMTP id md12so10811001pbc.21\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Apr 2014 05:59:44 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=sLA/eo+oalwo7mq/wx2zV958LJUsx3y51c3R8q57lOM=;\r
+ b=cczvDjyy/eSuq7dxhPSnzGtgfueFEYeUFb8TmzfkPPgw9hEO/p3cGZBQ/bhZfYOHzW\r
+ RTkj3CH55BdAaM1bU+3qbdB5VI516e3y+z72U7xuWpYl3hh+dLIQib/U0ClF7xCRt6Dc\r
+ NmugiUAZrnRW8v2/6mMLsbMCipA4j5xZvh++rpu4PQUfHoOhTDE51tNpTOlmMO0iaYmI\r
+ pwHPPfkmRspvTxXYpTb+80Uwu4LjSUzhgNEh6h6r/BZKJ97iltJoNzcH5Nb/U3cQFj3u\r
+ hI8KmID/UNJOoD/icBFBlDKftxzAn4nDL0/imMDmsnraU0ABZcUMqBgP2laIfPaexeXj\r
+ rjXQ==\r
+X-Received: by 10.68.221.42 with SMTP id qb10mr8324273pbc.65.1397653183958;\r
+ Wed, 16 Apr 2014 05:59:43 -0700 (PDT)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+ [220.233.42.215])\r
+ by mx.google.com with ESMTPSA id ja8sm46975039pbd.3.2014.04.16.05.59.41\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Wed, 16 Apr 2014 05:59:43 -0700 (PDT)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 01/10] lib: add return status to database close and destroy\r
+Date: Wed, 16 Apr 2014 22:59:16 +1000\r
+Message-Id: <1397653165-15620-2-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.8.4\r
+In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com>\r
+References: <1397653165-15620-1-git-send-email-novalazy@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 16 Apr 2014 12:59:53 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+notmuch_database_close may fail in Xapian ->flush() or ->close(), so\r
+report the status. Similarly for notmuch_database_destroy which calls\r
+close.\r
+\r
+This is required for notmuch insert to report error status if message\r
+indexing failed.\r
+---\r
+ lib/database.cc | 30 ++++++++++++++++++++++++------\r
+ lib/notmuch.h | 15 +++++++++++++--\r
+ 2 files changed, 37 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 1efb14d..ef7005b 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -774,14 +774,17 @@ notmuch_database_open (const char *path,\r
+ return status;\r
+ }\r
+ \r
+-void\r
++notmuch_status_t\r
+ notmuch_database_close (notmuch_database_t *notmuch)\r
+ {\r
++ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
++\r
+ try {\r
+ if (notmuch->xapian_db != NULL &&\r
+ notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
+ (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
+ } catch (const Xapian::Error &error) {\r
++ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ if (! notmuch->exception_reported) {\r
+ fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",\r
+ error.get_msg().c_str());\r
+@@ -795,7 +798,9 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+ try {\r
+ notmuch->xapian_db->close();\r
+ } catch (const Xapian::Error &error) {\r
+- /* do nothing */\r
++ /* don't clobber previous error status */\r
++ if (status == NOTMUCH_STATUS_SUCCESS)\r
++ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+ }\r
+ }\r
+ \r
+@@ -809,6 +814,8 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+ notmuch->value_range_processor = NULL;\r
+ delete notmuch->date_range_processor;\r
+ notmuch->date_range_processor = NULL;\r
++\r
++ return status;\r
+ }\r
+ \r
+ #if HAVE_XAPIAN_COMPACT\r
+@@ -972,8 +979,15 @@ notmuch_database_compact (const char *path,\r
+ }\r
+ \r
+ DONE:\r
+- if (notmuch)\r
+- notmuch_database_destroy (notmuch);\r
++ if (notmuch) {\r
++ notmuch_status_t ret2;\r
++\r
++ ret2 = notmuch_database_destroy (notmuch);\r
++\r
++ /* don't clobber previous error status */\r
++ if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS)\r
++ ret = ret2;\r
++ }\r
+ \r
+ talloc_free (local);\r
+ \r
+@@ -991,11 +1005,15 @@ notmuch_database_compact (unused (const char *path),\r
+ }\r
+ #endif\r
+ \r
+-void\r
++notmuch_status_t\r
+ notmuch_database_destroy (notmuch_database_t *notmuch)\r
+ {\r
+- notmuch_database_close (notmuch);\r
++ notmuch_status_t status;\r
++\r
++ status = notmuch_database_close (notmuch);\r
+ talloc_free (notmuch);\r
++\r
++ return status;\r
+ }\r
+ \r
+ const char *\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 350bed8..3c5ec98 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -287,8 +287,16 @@ notmuch_database_open (const char *path,\r
+ *\r
+ * notmuch_database_close can be called multiple times. Later calls\r
+ * have no effect.\r
++ *\r
++ * Return value:\r
++ *\r
++ * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.\r
++ *\r
++ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the\r
++ * database has been closed but there are no guarantees the\r
++ * changes to the database, if any, have been flushed to disk.\r
+ */\r
+-void\r
++notmuch_status_t\r
+ notmuch_database_close (notmuch_database_t *database);\r
+ \r
+ /**\r
+@@ -317,8 +325,11 @@ notmuch_database_compact (const char* path,\r
+ /**\r
+ * Destroy the notmuch database, closing it if necessary and freeing\r
+ * all associated resources.\r
++ *\r
++ * Return value as in notmuch_database_close if the database was open;\r
++ * notmuch_database_destroy itself has no failure modes.\r
+ */\r
+-void\r
++notmuch_status_t\r
+ notmuch_database_destroy (notmuch_database_t *database);\r
+ \r
+ /**\r
+-- \r
+1.8.4\r
+\r