notmuch_status_t
notmuch_database_upgrade (notmuch_database_t *notmuch,
void (*progress_notify) (void *closure,
- unsigned int count,
- unsigned int total),
+ double progress),
void *closure)
{
Xapian::WritableDatabase *db;
notmuch_bool_t timer_is_active = FALSE;
unsigned int version;
notmuch_status_t status;
+ unsigned int count = 0, total = 0;
status = _notmuch_database_ensure_writable (notmuch);
if (status)
* notmuch_message_add_filename.
*/
if (version < 1) {
- unsigned int count = 0, total;
notmuch_query_t *query = notmuch_query_create (notmuch, "");
notmuch_messages_t *messages;
notmuch_message_t *message;
char *filename;
+ Xapian::TermIterator t, t_end;
total = notmuch_query_count_messages (query);
notmuch_messages_advance (messages))
{
if (do_progress_notify) {
- progress_notify (closure, count, total);
+ progress_notify (closure, (double) count / total);
do_progress_notify = 0;
}
}
notmuch_query_destroy (query);
- }
- /* Also, before version 1 we stored directory timestamps in
- * XTIMESTAMP documents instead of the current XDIRECTORY
- * documents. So copy those as well. */
- if (version < 1) {
- Xapian::TermIterator t, t_end;
+ /* Also, before version 1 we stored directory timestamps in
+ * XTIMESTAMP documents instead of the current XDIRECTORY
+ * documents. So copy those as well. */
t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP");
time_t mtime;
notmuch_directory_t *directory;
+ if (do_progress_notify) {
+ progress_notify (closure, (double) count / total);
+ do_progress_notify = 0;
+ }
+
document = find_document_for_doc_id (notmuch, *p);
mtime = Xapian::sortable_unserialise (
document.get_value (NOTMUCH_VALUE_TIMESTAMP));
/* Now that the upgrade is complete we can remove the old data
* and documents that are no longer needed. */
if (version < 1) {
- unsigned int count = 0, total;
notmuch_query_t *query = notmuch_query_create (notmuch, "");
notmuch_messages_t *messages;
notmuch_message_t *message;
char *filename;
- total = notmuch_query_count_messages (query);
-
for (messages = notmuch_query_search_messages (query);
notmuch_messages_has_more (messages);
notmuch_messages_advance (messages))
{
if (do_progress_notify) {
- progress_notify (closure, count, total);
+ progress_notify (closure, (double) count / total);
do_progress_notify = 0;
}
talloc_free (filename);
notmuch_message_destroy (message);
-
- count++;
}
notmuch_query_destroy (query);
p != p_end;
p++)
{
+ if (do_progress_notify) {
+ progress_notify (closure, (double) count / total);
+ do_progress_notify = 0;
+ }
+
db->delete_document (*p);
}
}
static void
upgrade_print_progress (void *closure,
- unsigned int count,
- unsigned int total)
+ double progress)
{
add_files_state_t *state = closure;
- struct timeval tv_now;
- double elapsed_overall, rate_overall, time_remaining;
- gettimeofday (&tv_now, NULL);
+ printf ("Upgrading database: %.2f%% complete", progress * 100.0);
- elapsed_overall = notmuch_time_elapsed (state->tv_start, tv_now);
- rate_overall = count / elapsed_overall;
- time_remaining = ((total - count) / rate_overall);
+ if (progress > 0) {
+ struct timeval tv_now;
+ double elapsed, time_remaining;
+
+ gettimeofday (&tv_now, NULL);
+
+ elapsed = notmuch_time_elapsed (state->tv_start, tv_now);
+ time_remaining = (elapsed / progress) * (1.0 - progress);
+ printf (" (");
+ notmuch_time_print_formatted_seconds (time_remaining);
+ printf (" remaining)");
+ }
- printf ("Upgraded %d of %d messages (", count, total);
- notmuch_time_print_formatted_seconds (time_remaining);
- printf (" remaining). \r");
+ printf (". \r");
fflush (stdout);
}