notmuch_database_close may fail in Xapian ->flush() or ->close(), so
report the status. Similarly for notmuch_database_destroy which calls
close.
This is required for notmuch insert to report error status if message
indexing failed.
notmuch_database_close (notmuch_database_t *notmuch)
{
notmuch_database_close (notmuch_database_t *notmuch)
{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
+
try {
if (notmuch->xapian_db != NULL &&
notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
} catch (const Xapian::Error &error) {
try {
if (notmuch->xapian_db != NULL &&
notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
} catch (const Xapian::Error &error) {
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
if (! notmuch->exception_reported) {
fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
error.get_msg().c_str());
if (! notmuch->exception_reported) {
fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
error.get_msg().c_str());
try {
notmuch->xapian_db->close();
} catch (const Xapian::Error &error) {
try {
notmuch->xapian_db->close();
} catch (const Xapian::Error &error) {
+ /* don't clobber previous error status */
+ if (status == NOTMUCH_STATUS_SUCCESS)
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
notmuch->value_range_processor = NULL;
delete notmuch->date_range_processor;
notmuch->date_range_processor = NULL;
notmuch->value_range_processor = NULL;
delete notmuch->date_range_processor;
notmuch->date_range_processor = NULL;
}
#if HAVE_XAPIAN_COMPACT
}
#if HAVE_XAPIAN_COMPACT
- if (notmuch)
- notmuch_database_destroy (notmuch);
+ if (notmuch) {
+ notmuch_status_t ret2;
+
+ ret2 = notmuch_database_destroy (notmuch);
+
+ /* don't clobber previous error status */
+ if (ret == NOTMUCH_STATUS_SUCCESS && ret2 != NOTMUCH_STATUS_SUCCESS)
+ ret = ret2;
+ }
notmuch_database_destroy (notmuch_database_t *notmuch)
{
notmuch_database_destroy (notmuch_database_t *notmuch)
{
- notmuch_database_close (notmuch);
+ notmuch_status_t status;
+
+ status = notmuch_database_close (notmuch);
*
* notmuch_database_close can be called multiple times. Later calls
* have no effect.
*
* notmuch_database_close can be called multiple times. Later calls
* have no effect.
+ *
+ * Return value:
+ *
+ * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the
+ * database has been closed but there are no guarantees the
+ * changes to the database, if any, have been flushed to disk.
notmuch_database_close (notmuch_database_t *database);
/**
notmuch_database_close (notmuch_database_t *database);
/**
/**
* Destroy the notmuch database, closing it if necessary and freeing
* all associated resources.
/**
* Destroy the notmuch database, closing it if necessary and freeing
* all associated resources.
+ *
+ * Return value as in notmuch_database_close if the database was open;
+ * notmuch_database_destroy itself has no failure modes.
notmuch_database_destroy (notmuch_database_t *database);
/**
notmuch_database_destroy (notmuch_database_t *database);
/**