X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=dd1fc6378c48c8b435eab97a0cede52ebc975f0a;hp=6afc8d938e382eb054d8088bd067d03193547ef0;hb=98845fdbb2a4acaa0036f8e2e998e726b18e6b13;hpb=361b9d4bd9042629e3729b43d18a862ddc716242 diff --git a/lib/database.cc b/lib/database.cc index 6afc8d93..dd1fc637 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -622,6 +622,7 @@ notmuch_database_open (const char *path, } } + 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; @@ -1169,6 +1170,31 @@ notmuch_database_get_directory (notmuch_database_t *notmuch, } } +/* Allocate a document ID that satisfies the following criteria: + * + * 1. The ID does not exist for any document in the Xapian database + * + * 2. The ID was not previously returned from this function + * + * 3. The ID is the smallest integer satisfying (1) and (2) + * + * This function will trigger an internal error if these constraints + * cannot all be satisfied, (that is, the pool of available document + * IDs has been exhausted). + */ +unsigned int +_notmuch_database_generate_doc_id (notmuch_database_t *notmuch) +{ + assert (notmuch->last_doc_id >= notmuch->xapian_db->get_lastdocid ()); + + notmuch->last_doc_id++; + + if (notmuch->last_doc_id == 0) + INTERNAL_ERROR ("Xapian document IDs are exhausted.\n"); + + return notmuch->last_doc_id; +} + static const char * _notmuch_database_generate_thread_id (notmuch_database_t *notmuch) {