aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2017-02-23 21:38:24 -0400
committerDavid Bremner <david@tethera.net>2017-02-25 21:09:17 -0400
commite17a914b77230d942b36639c261c345849fe9d52 (patch)
tree4339301315d1ae8845dc09601ed8a0d3ec014785 /lib/database.cc
parentae731c183a64c1b68ceb145417897ae1c32b4971 (diff)
lib: add _notmuch_database_reopen
The main expected use is to recover from a Xapian::DatabaseChanged exception.
Diffstat (limited to 'lib/database.cc')
-rw-r--r--lib/database.cc23
1 files changed, 23 insertions, 0 deletions
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),