mail-index-transaction-finish.c revision d97f939b1c09e9f90b01b6f81bfb1c05da990148
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen/* Copyright (c) 2003-2017 Dovecot authors, see the included COPYING file */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenint mail_transaction_expunge_guid_cmp(const struct mail_transaction_expunge_guid *e1,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen const struct mail_transaction_expunge_guid *e2)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenvoid mail_index_transaction_sort_expunges(struct mail_index_transaction *t)
a1761856683b4bf745eb4e32cefabeb851efb301Timo Sirainen array_sort(&t->expunges, mail_transaction_expunge_guid_cmp);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenext_reset_update_atomic(struct mail_index_transaction *t,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen if (!mail_index_map_get_ext_idx(t->view->index->map, ext_id, &idx)) {
3d4450c252790b03bb5ce054987ac91110f1ff62Timo Sirainen /* new extension */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen map_ext = array_idx(&t->view->index->map->extensions, idx);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen /* ignore this extension update */
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainen array_idx_set(&t->ext_reset_ids, ext_id, &reset_id);
85a4ae7e8df7ea45a7665828e5edf48a5fc85730Timo Sirainen /* reseting existing data is optional */
fda168427e1950518acd6d600f1a10a29a5baef0Timo Sirainen reset = array_idx_modifiable(&t->ext_resets, ext_id);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainentransaction_update_atomic_reset_ids(struct mail_index_transaction *t)
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen expected_reset_ids = array_get(&t->ext_reset_atomic, &count);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenstatic unsigned int
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenmail_transaction_drop_range(struct mail_index_transaction *t,
3fb1c1f0375ec0a2b00be90b5d61fbc8374e9b90Timo Sirainen unsigned int i, keep_count;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* evereything is kept */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* add back all the updates we want to keep */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen for (i = 0; i < keep_count; i++, update_idx++) {
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen array_insert(&t->updates, update_idx, &update, 1);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenmail_index_transaction_finish_flag_updates(struct mail_index_transaction *t)
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen const struct mail_index_flag_update *updates, *u;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen unsigned int i, count;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen if (!t->drop_unnecessary_flag_updates || !array_is_created(&t->updates))
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen for (i = 0; i < count; ) {
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen /* first get the list of changes to drop */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen if ((rec->flags & u->add_flags) != u->add_flags ||
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* keep this change */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen i = mail_transaction_drop_range(t, updates[i], i, &keeps);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenmail_index_transaction_check_conflicts(struct mail_index_transaction *t)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen if (t->max_modseq == mail_index_modseq_get_highest(t->view)) {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* no conflicts possible */
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* no flag updates */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen for (seq = t->min_flagupdate_seq; seq <= t->max_flagupdate_seq; seq++) {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen if (mail_index_modseq_lookup(t->view, seq) > t->max_modseq) {
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen ret1 = mail_index_cancel_flag_updates(t, seq);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen ret2 = mail_index_cancel_keyword_updates(t, seq);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen seq_range_array_add_with_init(t->conflict_seqs,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenmail_index_transaction_get_uid(struct mail_index_transaction *t, uint32_t seq)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen i_assert(seq <= t->view->map->hdr.messages_count);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen rec = MAIL_INDEX_REC_AT_SEQ(t->view->map, seq);
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainenmail_index_convert_to_uids(struct mail_index_transaction *t,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen unsigned int i, count;
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen for (i = 0; i < count; i++) {
0f55802e8fdd95ae4290da6da077819209b71f70Timo Sirainen *seq = mail_index_transaction_get_uid(t, *seq);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainenget_nonexpunged_uid2(struct mail_index_transaction *t,
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen while (mail_index_transaction_get_uid(t, seq1) == uid1 + 1) {
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenvoid mail_index_transaction_seq_range_to_uid(struct mail_index_transaction *t,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen unsigned int i, count;
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen for (i = 0; i < count; i++) {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen uid1 = mail_index_transaction_get_uid(t, range->seq1);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen uid2 = mail_index_transaction_get_uid(t, range->seq2);
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen if (uid2 - uid1 == range->seq2 - range->seq1) {
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen /* simple conversion */
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen /* remove expunged UIDs */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen memcpy(new_range, range, array->arr.element_size);
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen new_range->seq2 = get_nonexpunged_uid2(t, uid1,
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen /* continue the range without the inserted seqs */
c06cd6539a3dbd68eb546464076187be6bc4290fTimo Sirainen range->seq1 += new_range->seq2 - new_range->seq1 + 1;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic void keyword_updates_convert_to_uids(struct mail_index_transaction *t)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct mail_index_transaction_keyword_update *update;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen array_foreach_modifiable(&t->keyword_updates, update) {
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mail_index_transaction_seq_range_to_uid(t, &update->add_seq);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mail_index_transaction_seq_range_to_uid(t, &update->remove_seq);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenstatic void expunges_convert_to_uids(struct mail_index_transaction *t)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen struct mail_transaction_expunge_guid *expunges;
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen expunges = array_get_modifiable(&t->expunges, &count);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen /* convert uids and drop duplicates */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen expunges[0].uid = mail_index_transaction_get_uid(t, expunges[0].uid);
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen mail_index_transaction_get_uid(t, expunges[src].uid);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen if (expunges[dest-1].uid != expunges[dest].uid) {
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen memcpy(expunges[dest].guid_128, expunges[src].guid_128,
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenmail_index_transaction_convert_to_uids(struct mail_index_transaction *t)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen array_foreach_modifiable(&t->ext_rec_updates, update)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen array_foreach_modifiable(&t->ext_rec_atomics, update)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mail_index_convert_to_uids(t, (void *)&t->modseq_updates);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mail_index_transaction_seq_range_to_uid(t, (void *)&t->updates);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenvoid mail_index_transaction_finish_so_far(struct mail_index_transaction *t)
2793e3bd31d212d6506686aa70773e13d9d98195Timo Sirainen mail_index_transaction_finish_flag_updates(t);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainenvoid mail_index_transaction_finish(struct mail_index_transaction *t)
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen mail_index_update_day_headers(t, ioloop_time);
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen /* finally convert all sequences to UIDs before we write them,
eb0ede66120bb63c0212bad69e67efca1eb47324Timo Sirainen but after we've checked and removed conflicts */
88dc563319efecd6e68bad16b0d92672da05584aTimo Sirainen /* and kind of ugly way to update highest modseq */