mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
lib: add return status to database close and destroy
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.
This commit is contained in:
parent
6721222ea8
commit
ab24e883b0
2 changed files with 37 additions and 8 deletions
|
@ -774,14 +774,17 @@ notmuch_database_open (const char *path,
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
notmuch_status_t
|
||||||
notmuch_database_close (notmuch_database_t *notmuch)
|
notmuch_database_close (notmuch_database_t *notmuch)
|
||||||
{
|
{
|
||||||
|
notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (notmuch->xapian_db != NULL &&
|
if (notmuch->xapian_db != NULL &&
|
||||||
notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
|
notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
|
||||||
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
|
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
|
||||||
} catch (const Xapian::Error &error) {
|
} catch (const Xapian::Error &error) {
|
||||||
|
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
|
||||||
if (! notmuch->exception_reported) {
|
if (! notmuch->exception_reported) {
|
||||||
fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
|
fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
|
||||||
error.get_msg().c_str());
|
error.get_msg().c_str());
|
||||||
|
@ -795,7 +798,9 @@ notmuch_database_close (notmuch_database_t *notmuch)
|
||||||
try {
|
try {
|
||||||
notmuch->xapian_db->close();
|
notmuch->xapian_db->close();
|
||||||
} catch (const Xapian::Error &error) {
|
} catch (const Xapian::Error &error) {
|
||||||
/* do nothing */
|
/* don't clobber previous error status */
|
||||||
|
if (status == NOTMUCH_STATUS_SUCCESS)
|
||||||
|
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,6 +814,8 @@ notmuch_database_close (notmuch_database_t *notmuch)
|
||||||
notmuch->value_range_processor = NULL;
|
notmuch->value_range_processor = NULL;
|
||||||
delete notmuch->date_range_processor;
|
delete notmuch->date_range_processor;
|
||||||
notmuch->date_range_processor = NULL;
|
notmuch->date_range_processor = NULL;
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_XAPIAN_COMPACT
|
#if HAVE_XAPIAN_COMPACT
|
||||||
|
@ -972,8 +979,15 @@ notmuch_database_compact (const char *path,
|
||||||
}
|
}
|
||||||
|
|
||||||
DONE:
|
DONE:
|
||||||
if (notmuch)
|
if (notmuch) {
|
||||||
notmuch_database_destroy (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;
|
||||||
|
}
|
||||||
|
|
||||||
talloc_free (local);
|
talloc_free (local);
|
||||||
|
|
||||||
|
@ -991,11 +1005,15 @@ notmuch_database_compact (unused (const char *path),
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
notmuch_status_t
|
||||||
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);
|
||||||
talloc_free (notmuch);
|
talloc_free (notmuch);
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
|
@ -287,8 +287,16 @@ notmuch_database_open (const char *path,
|
||||||
*
|
*
|
||||||
* notmuch_database_close can be called multiple times. Later calls
|
* notmuch_database_close can be called multiple times. Later calls
|
||||||
* have no effect.
|
* 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.
|
||||||
*/
|
*/
|
||||||
void
|
notmuch_status_t
|
||||||
notmuch_database_close (notmuch_database_t *database);
|
notmuch_database_close (notmuch_database_t *database);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -317,8 +325,11 @@ notmuch_database_compact (const char* path,
|
||||||
/**
|
/**
|
||||||
* Destroy the notmuch database, closing it if necessary and freeing
|
* Destroy the notmuch database, closing it if necessary and freeing
|
||||||
* all associated resources.
|
* all associated resources.
|
||||||
|
*
|
||||||
|
* Return value as in notmuch_database_close if the database was open;
|
||||||
|
* notmuch_database_destroy itself has no failure modes.
|
||||||
*/
|
*/
|
||||||
void
|
notmuch_status_t
|
||||||
notmuch_database_destroy (notmuch_database_t *database);
|
notmuch_database_destroy (notmuch_database_t *database);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue