Skip to content

Commit

Permalink
lib-index: Add mail_index_append_finish_uids_full()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Jan 23, 2019
1 parent abc33be commit 19313d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/lib-index/mail-index-transaction-update.c
Expand Up @@ -194,6 +194,14 @@ void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
void mail_index_append_finish_uids(struct mail_index_transaction *t,
uint32_t first_uid,
ARRAY_TYPE(seq_range) *uids_r)
{
return mail_index_append_finish_uids_full(t, first_uid, first_uid, uids_r);
}

void mail_index_append_finish_uids_full(struct mail_index_transaction *t,
uint32_t min_allowed_uid,
uint32_t first_new_uid,
ARRAY_TYPE(seq_range) *uids_r)
{
struct mail_index_record *recs;
unsigned int i, count;
Expand All @@ -203,13 +211,14 @@ void mail_index_append_finish_uids(struct mail_index_transaction *t,
if (!array_is_created(&t->appends))
return;

i_assert(first_uid < (uint32_t)-1);
i_assert(min_allowed_uid <= first_new_uid);
i_assert(first_new_uid < (uint32_t)-1);

/* first find the highest assigned uid */
recs = array_get_modifiable(&t->appends, &count);
i_assert(count > 0);

next_uid = first_uid;
next_uid = first_new_uid;
for (i = 0; i < count; i++) {
if (next_uid <= recs[i].uid)
next_uid = recs[i].uid + 1;
Expand All @@ -218,7 +227,7 @@ void mail_index_append_finish_uids(struct mail_index_transaction *t,

/* assign missing uids */
for (i = 0; i < count; i++) {
if (recs[i].uid == 0 || recs[i].uid < first_uid) {
if (recs[i].uid == 0 || recs[i].uid < min_allowed_uid) {
i_assert(next_uid < (uint32_t)-1);
recs[i].uid = next_uid++;
if (t->highest_append_uid < recs[i].uid)
Expand Down
16 changes: 11 additions & 5 deletions src/lib-index/mail-index.h
Expand Up @@ -555,11 +555,17 @@ void mail_index_lookup_first(struct mail_index_view *view,
/* Append a new record to index. */
void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
uint32_t *seq_r);
/* Assign UIDs for mails with uid=0 or uid<first_uid. All the assigned UIDs
are higher than the highest unassigned UID (i.e. it doesn't try to fill UID
gaps). Assumes that mailbox is locked in a way that UIDs can be safely
assigned. Returns UIDs for all assigned messages, in their sequence order
(so UIDs are not necessary ascending). */
/* Assign new UIDs for mails with uid=0 or uid<min_allowed_uid. All the new
UIDs are >= first_new_uid, an also higher than the highest seen uid (i.e. it
doesn't try to fill UID gaps). Assumes that mailbox is locked in a way that
UIDs can be safely assigned. Returns UIDs for all assigned messages, in
their sequence order (so UIDs are not necessary ascending). */
void mail_index_append_finish_uids_full(struct mail_index_transaction *t,
uint32_t min_allowed_uid,
uint32_t first_new_uid,
ARRAY_TYPE(seq_range) *uids_r);
/* Call mail_index_append_finish_uids_full() with first_uid used for both
min_allowed_uid and first_new_uid. */
void mail_index_append_finish_uids(struct mail_index_transaction *t,
uint32_t first_uid,
ARRAY_TYPE(seq_range) *uids_r);
Expand Down

0 comments on commit 19313d7

Please sign in to comment.