]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index_revert_changes()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 13 Dec 2016 16:31:41 +0000 (18:31 +0200)
committerGitLab <gitlab@git.dovecot.net>
Wed, 14 Dec 2016 15:24:06 +0000 (17:24 +0200)
This can be used to revert changes done in a transaction to the specified
existing mail.

src/lib-index/mail-index-transaction-update.c
src/lib-index/mail-index.h

index 58f6e3e9190b2ab1f3b1ff3798723f0c5ed65b80..6e9becc2b90ee4cb9e8d2f00c48706b3d2bf8954 100644 (file)
@@ -282,8 +282,8 @@ void mail_index_update_highest_modseq(struct mail_index_transaction *t,
 }
 
 static void
-mail_index_expunge_last_append_ext(ARRAY_TYPE(seq_array_array) *ext_updates,
-                                  uint32_t seq)
+mail_index_revert_ext(ARRAY_TYPE(seq_array_array) *ext_updates,
+                     uint32_t seq)
 {
        ARRAY_TYPE(seq_array) *seqs;
        unsigned int idx;
@@ -299,16 +299,14 @@ mail_index_expunge_last_append_ext(ARRAY_TYPE(seq_array_array) *ext_updates,
 }
 
 static void
-mail_index_expunge_last_append(struct mail_index_transaction *t, uint32_t seq)
+mail_index_revert_changes_common(struct mail_index_transaction *t, uint32_t seq)
 {
        struct mail_index_transaction_keyword_update *kw_update;
        unsigned int i;
 
-       i_assert(seq == t->last_new_seq);
-
        /* remove extension updates */
-       mail_index_expunge_last_append_ext(&t->ext_rec_updates, seq);
-       mail_index_expunge_last_append_ext(&t->ext_rec_atomics, seq);
+       mail_index_revert_ext(&t->ext_rec_updates, seq);
+       mail_index_revert_ext(&t->ext_rec_atomics, seq);
        t->log_ext_updates = mail_index_transaction_has_ext_changes(t);
 
        /* remove keywords */
@@ -328,6 +326,20 @@ mail_index_expunge_last_append(struct mail_index_transaction *t, uint32_t seq)
        if (array_is_created(&t->modseq_updates) &&
            mail_index_seq_array_lookup((void *)&t->modseq_updates, seq, &i))
                array_delete(&t->modseq_updates, i, 1);
+}
+
+void mail_index_revert_changes(struct mail_index_transaction *t, uint32_t seq)
+{
+       mail_index_revert_changes_common(t, seq);
+       mail_index_cancel_flag_updates(t, seq);
+}
+
+static void
+mail_index_expunge_last_append(struct mail_index_transaction *t, uint32_t seq)
+{
+       i_assert(seq == t->last_new_seq);
+
+       mail_index_revert_changes_common(t, seq);
 
        /* and finally remove the append itself */
        array_delete(&t->appends, seq - t->first_new_seq, 1);
index 0f1dec565c371d2104e79ec67a5bda2a29424650..41106abf8a2e68a0ed6353a8e9c7519f7c40bf67 100644 (file)
@@ -497,6 +497,8 @@ void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq);
 /* Like mail_index_expunge(), but also write message GUID to transaction log. */
 void mail_index_expunge_guid(struct mail_index_transaction *t, uint32_t seq,
                             const guid_128_t guid_128);
+/* Revert all changes done in this transaction to the given existing mail. */
+void mail_index_revert_changes(struct mail_index_transaction *t, uint32_t seq);
 /* Update flags in index. */
 void mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
                             enum modify_type modify_type,