mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
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.
This commit is contained in:
parent
0729c4e81f
commit
393c92b042
2 changed files with 34 additions and 26 deletions
59
lib/open.cc
59
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
|
static notmuch_status_t
|
||||||
_finish_open (notmuch_database_t *notmuch,
|
_finish_open (notmuch_database_t *notmuch,
|
||||||
const char *profile,
|
const char *profile,
|
||||||
|
@ -339,8 +370,6 @@ _finish_open (notmuch_database_t *notmuch,
|
||||||
const char *database_path = notmuch_database_get_path (notmuch);
|
const char *database_path = notmuch_database_get_path (notmuch);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::string last_thread_id;
|
|
||||||
std::string last_mod;
|
|
||||||
|
|
||||||
if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
|
if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
|
||||||
notmuch->writable_xapian_db = new Xapian::WritableDatabase (notmuch->xapian_path,
|
notmuch->writable_xapian_db = new Xapian::WritableDatabase (notmuch->xapian_path,
|
||||||
|
@ -384,29 +413,7 @@ _finish_open (notmuch_database_t *notmuch,
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch->last_doc_id = notmuch->xapian_db->get_lastdocid ();
|
_load_database_state (notmuch);
|
||||||
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 ());
|
|
||||||
|
|
||||||
notmuch->query_parser = new Xapian::QueryParser;
|
notmuch->query_parser = new Xapian::QueryParser;
|
||||||
notmuch->term_gen = new Xapian::TermGenerator;
|
notmuch->term_gen = new Xapian::TermGenerator;
|
||||||
|
@ -733,6 +740,8 @@ notmuch_database_reopen (notmuch_database_t *notmuch,
|
||||||
DB_ACTION);
|
DB_ACTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_load_database_state (notmuch);
|
||||||
} catch (const Xapian::Error &error) {
|
} catch (const Xapian::Error &error) {
|
||||||
if (! notmuch->exception_reported) {
|
if (! notmuch->exception_reported) {
|
||||||
_notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n",
|
_notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n",
|
||||||
|
|
|
@ -187,7 +187,6 @@ EOF
|
||||||
test_expect_equal_file write.expected write.output
|
test_expect_equal_file write.expected write.output
|
||||||
|
|
||||||
test_begin_subtest "add message in pre-new [${config}]"
|
test_begin_subtest "add message in pre-new [${config}]"
|
||||||
test_subtest_known_broken
|
|
||||||
rm -rf ${HOOK_DIR}
|
rm -rf ${HOOK_DIR}
|
||||||
generate_message '[subject]="add msg in pre-new"'
|
generate_message '[subject]="add msg in pre-new"'
|
||||||
id1=$gen_msg_id
|
id1=$gen_msg_id
|
||||||
|
|
Loading…
Reference in a new issue