From: David Bremner Date: Fri, 24 Feb 2017 01:38:24 +0000 (-0400) Subject: lib: add _notmuch_database_reopen X-Git-Tag: 0.24_rc0~30 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=e17a914b77230d942b36639c261c345849fe9d52 lib: add _notmuch_database_reopen The main expected use is to recover from a Xapian::DatabaseChanged exception. --- diff --git a/lib/database-private.h b/lib/database-private.h index 2fb60f5e..06882439 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -207,6 +207,10 @@ struct _notmuch_database { unsigned long revision; const char *uuid; + /* Keep track of the number of times the database has been re-opened + * (or other global invalidations of notmuch's caching) + */ + unsigned long view; Xapian::QueryParser *query_parser; Xapian::TermGenerator *term_gen; Xapian::ValueRangeProcessor *value_range_processor; diff --git a/lib/database.cc b/lib/database.cc index 386dcd17..ba440d4d 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -951,6 +951,7 @@ notmuch_database_open_verbose (const char *path, notmuch->mode = mode; notmuch->atomic_nesting = 0; + notmuch->view = 1; try { string last_thread_id; string last_mod; @@ -1133,6 +1134,28 @@ notmuch_database_close (notmuch_database_t *notmuch) return status; } +notmuch_status_t +_notmuch_database_reopen (notmuch_database_t *notmuch) +{ + if (notmuch->mode != NOTMUCH_DATABASE_MODE_READ_ONLY) + return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; + + try { + notmuch->xapian_db->reopen (); + } catch (const Xapian::Error &error) { + if (! notmuch->exception_reported) { + _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n", + error.get_msg ().c_str ()); + notmuch->exception_reported = TRUE; + } + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } + + notmuch->view++; + + return NOTMUCH_STATUS_SUCCESS; +} + static int unlink_cb (const char *path, unused (const struct stat *sb), diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 7b35fc5b..8587e86c 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -192,6 +192,9 @@ _notmuch_message_id_compressed (void *ctx, const char *message_id); notmuch_status_t _notmuch_database_ensure_writable (notmuch_database_t *notmuch); +notmuch_status_t +_notmuch_database_reopen (notmuch_database_t *notmuch); + void _notmuch_database_log (notmuch_database_t *notmuch, const char *format, ...);