aboutsummaryrefslogtreecommitdiff
path: root/lib/open.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-05-09 09:28:48 -0300
committerDavid Bremner <david@tethera.net>2021-05-12 08:40:04 -0300
commit393c92b04271472e6fdd19da73672a60723e34aa (patch)
treeaabc5646972d5aa7310b12074409f596cca7ec5f /lib/open.cc
parent0729c4e81f094eb6c81ba7c4287d90726c89d619 (diff)
lib/notmuch_database_reopen: reload some database metadata
In some uses of reopen, new documents and threads maybe have been added, and e.g. compaction may have changed the uuid.
Diffstat (limited to 'lib/open.cc')
-rw-r--r--lib/open.cc59
1 files changed, 34 insertions, 25 deletions
diff --git a/lib/open.cc b/lib/open.cc
index bdb695fe..1e9c86fe 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -325,6 +325,37 @@ _init_libs ()
}
}
+static void
+_load_database_state (notmuch_database_t *notmuch)
+{
+ std::string last_thread_id;
+ std::string last_mod;
+
+ notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid ();
+ last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id");
+ if (last_thread_id.empty ()) {
+ notmuch->last_thread_id = 0;
+ } else {
+ const char *str;
+ char *end;
+
+ str = last_thread_id.c_str ();
+ notmuch->last_thread_id = strtoull (str, &end, 16);
+ if (*end != '\0')
+ INTERNAL_ERROR ("Malformed database last_thread_id: %s", str);
+ }
+
+ /* Get current highest revision number. */
+ last_mod = notmuch->xapian_db->get_value_upper_bound (
+ NOTMUCH_VALUE_LAST_MOD);
+ if (last_mod.empty ())
+ notmuch->revision = 0;
+ else
+ notmuch->revision = Xapian::sortable_unserialise (last_mod);
+ notmuch->uuid = talloc_strdup (
+ notmuch, notmuch->xapian_db->get_uuid ().c_str ());
+}
+
static notmuch_status_t
_finish_open (notmuch_database_t *notmuch,
const char *profile,
@@ -339,8 +370,6 @@ _finish_open (notmuch_database_t *notmuch,
const char *database_path = notmuch_database_get_path (notmuch);
try {
- std::string last_thread_id;
- std::string last_mod;
if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
notmuch->writable_xapian_db = new Xapian::WritableDatabase (notmuch->xapian_path,
@@ -384,29 +413,7 @@ _finish_open (notmuch_database_t *notmuch,
goto DONE;
}
- notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid ();
- last_thread_id = notmuch->xapian_db->get_metadata ("last_thread_id");
- if (last_thread_id.empty ()) {
- notmuch->last_thread_id = 0;
- } else {
- const char *str;
- char *end;
-
- str = last_thread_id.c_str ();
- notmuch->last_thread_id = strtoull (str, &end, 16);
- if (*end != '\0')
- INTERNAL_ERROR ("Malformed database last_thread_id: %s", str);
- }
-
- /* Get current highest revision number. */
- last_mod = notmuch->xapian_db->get_value_upper_bound (
- NOTMUCH_VALUE_LAST_MOD);
- if (last_mod.empty ())
- notmuch->revision = 0;
- else
- notmuch->revision = Xapian::sortable_unserialise (last_mod);
- notmuch->uuid = talloc_strdup (
- notmuch, notmuch->xapian_db->get_uuid ().c_str ());
+ _load_database_state (notmuch);
notmuch->query_parser = new Xapian::QueryParser;
notmuch->term_gen = new Xapian::TermGenerator;
@@ -733,6 +740,8 @@ notmuch_database_reopen (notmuch_database_t *notmuch,
DB_ACTION);
}
}
+
+ _load_database_state (notmuch);
} catch (const Xapian::Error &error) {
if (! notmuch->exception_reported) {
_notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n",