mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 10:58:10 +01:00
lib: Implement upgrade to ghost messages feature
Somehow this is the first upgrade pass that actually does *any* error checking, so this also adds the bit of necessary infrastructure to handle that.
This commit is contained in:
parent
58a4277d3b
commit
d1e8c80b72
1 changed files with 64 additions and 2 deletions
|
@ -1231,6 +1231,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
notmuch_bool_t timer_is_active = FALSE;
|
notmuch_bool_t timer_is_active = FALSE;
|
||||||
enum _notmuch_features target_features, new_features;
|
enum _notmuch_features target_features, new_features;
|
||||||
notmuch_status_t status;
|
notmuch_status_t status;
|
||||||
|
notmuch_private_status_t private_status;
|
||||||
unsigned int count = 0, total = 0;
|
unsigned int count = 0, total = 0;
|
||||||
|
|
||||||
status = _notmuch_database_ensure_writable (notmuch);
|
status = _notmuch_database_ensure_writable (notmuch);
|
||||||
|
@ -1275,6 +1276,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++)
|
for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++)
|
||||||
++total;
|
++total;
|
||||||
}
|
}
|
||||||
|
if (new_features & NOTMUCH_FEATURE_GHOSTS) {
|
||||||
|
/* The ghost message upgrade converts all thread_id_*
|
||||||
|
* metadata values into ghost message documents. */
|
||||||
|
t_end = db->metadata_keys_end ("thread_id_");
|
||||||
|
for (t = db->metadata_keys_begin ("thread_id_"); t != t_end; ++t)
|
||||||
|
++total;
|
||||||
|
}
|
||||||
|
|
||||||
/* Perform the upgrade in a transaction. */
|
/* Perform the upgrade in a transaction. */
|
||||||
db->begin_transaction (true);
|
db->begin_transaction (true);
|
||||||
|
@ -1378,10 +1386,64 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Perform metadata upgrades. */
|
||||||
|
|
||||||
|
/* Prior to NOTMUCH_FEATURE_GHOSTS, thread IDs for missing
|
||||||
|
* messages were stored as database metadata. Change these to
|
||||||
|
* ghost messages.
|
||||||
|
*/
|
||||||
|
if (new_features & NOTMUCH_FEATURE_GHOSTS) {
|
||||||
|
notmuch_message_t *message;
|
||||||
|
std::string message_id, thread_id;
|
||||||
|
|
||||||
|
t_end = db->metadata_keys_end (NOTMUCH_METADATA_THREAD_ID_PREFIX);
|
||||||
|
for (t = db->metadata_keys_begin (NOTMUCH_METADATA_THREAD_ID_PREFIX);
|
||||||
|
t != t_end; ++t) {
|
||||||
|
if (do_progress_notify) {
|
||||||
|
progress_notify (closure, (double) count / total);
|
||||||
|
do_progress_notify = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
message_id = (*t).substr (
|
||||||
|
strlen (NOTMUCH_METADATA_THREAD_ID_PREFIX));
|
||||||
|
thread_id = db->get_metadata (*t);
|
||||||
|
|
||||||
|
/* Create ghost message */
|
||||||
|
message = _notmuch_message_create_for_message_id (
|
||||||
|
notmuch, message_id.c_str (), &private_status);
|
||||||
|
if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) {
|
||||||
|
/* Document already exists; ignore the stored thread ID */
|
||||||
|
} else if (private_status ==
|
||||||
|
NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
|
||||||
|
private_status = _notmuch_message_initialize_ghost (
|
||||||
|
message, thread_id.c_str ());
|
||||||
|
if (! private_status)
|
||||||
|
_notmuch_message_sync (message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (private_status) {
|
||||||
|
fprintf (stderr,
|
||||||
|
"Upgrade failed while creating ghost messages.\n");
|
||||||
|
status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear saved metadata thread ID */
|
||||||
|
db->set_metadata (*t, "");
|
||||||
|
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status = NOTMUCH_STATUS_SUCCESS;
|
||||||
db->set_metadata ("features", _print_features (local, notmuch->features));
|
db->set_metadata ("features", _print_features (local, notmuch->features));
|
||||||
db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));
|
db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));
|
||||||
|
|
||||||
|
DONE:
|
||||||
|
if (status == NOTMUCH_STATUS_SUCCESS)
|
||||||
db->commit_transaction ();
|
db->commit_transaction ();
|
||||||
|
else
|
||||||
|
db->cancel_transaction ();
|
||||||
|
|
||||||
if (timer_is_active) {
|
if (timer_is_active) {
|
||||||
/* Now stop the timer. */
|
/* Now stop the timer. */
|
||||||
|
@ -1397,7 +1459,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
|
||||||
}
|
}
|
||||||
|
|
||||||
talloc_free (local);
|
talloc_free (local);
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
|
|
Loading…
Reference in a new issue