bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "lib.h"
e05a4c4136fec723f019bee8383103080203f127Timo Sirainen#include "array.h"
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen#include "dict.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "index-storage.h"
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen#include "index-sync-private.h"
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen#include "index-pop3-uidl.h"
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen#include "index-mail.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenstatic void index_transaction_free(struct mailbox_transaction_context *t)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen{
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if (t->view_pvt != NULL)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen mail_index_view_close(&t->view_pvt);
128ea07dab8d67124ea74bcc085a478784b6358aTimo Sirainen mail_cache_view_close(&t->cache_view);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen mail_index_view_close(&t->view);
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen if (array_is_created(&t->pvt_saves))
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen array_free(&t->pvt_saves);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen array_free(&t->module_contexts);
d1fbd2c264368d8b4c7139b96e3b21f45930b857Timo Sirainen i_free(t->reason);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_free(t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainenstatic int
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainenindex_transaction_index_commit(struct mail_index_transaction *index_trans,
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen struct mail_index_transaction_commit_result *result_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen{
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mailbox_transaction_context *t =
c51390c3ae6e373e7b4a052a94e8e4065b98321cAki Tuomi MAIL_STORAGE_CONTEXT_REQUIRE(index_trans);
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen struct index_mailbox_sync_pvt_context *pvt_sync_ctx = NULL;
661998e2ccd772ad92a9d4a75cb712692a8c94b3Timo Sirainen const char *error;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen int ret = 0;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
2b9dbb270ad82e58d5f3581436e6f143176d5819Timo Sirainen index_pop3_uidl_update_exists_finish(t);
900bb5e316d030cdebff7ee128ce65881dfb27f7Timo Sirainen
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen if (t->attr_pvt_trans != NULL) {
661998e2ccd772ad92a9d4a75cb712692a8c94b3Timo Sirainen if (dict_transaction_commit(&t->attr_pvt_trans, &error) < 0) {
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi mailbox_set_critical(t->box,
661998e2ccd772ad92a9d4a75cb712692a8c94b3Timo Sirainen "Dict private transaction commit failed: %s", error);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen ret = -1;
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen }
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen }
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen if (t->attr_shared_trans != NULL) {
661998e2ccd772ad92a9d4a75cb712692a8c94b3Timo Sirainen if (dict_transaction_commit(&t->attr_shared_trans, &error) < 0) {
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi mailbox_set_critical(t->box,
661998e2ccd772ad92a9d4a75cb712692a8c94b3Timo Sirainen "Dict shared transaction commit failed: %s", error);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen ret = -1;
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen }
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen }
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen if (t->save_ctx != NULL) {
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen mailbox_save_context_deinit(t->save_ctx);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen if (ret < 0) {
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen t->box->v.transaction_save_rollback(t->save_ctx);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen t->save_ctx = NULL;
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen } else if (t->box->v.transaction_save_commit_pre(t->save_ctx) < 0) {
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen t->save_ctx = NULL;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen ret = -1;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen }
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen }
01937f71b3ae0d5b30b813372f44a3e7e86c89dcTimo Sirainen
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen if (array_is_created(&t->pvt_saves)) {
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen if (index_mailbox_sync_pvt_init(t->box, TRUE, &pvt_sync_ctx) < 0)
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen ret = -1;
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen }
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen i_assert(t->mail_ref_count == 0);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (ret < 0)
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen t->super.rollback(index_trans);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen else {
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen if (t->super.commit(index_trans, result_r) < 0) {
1f1ee8db68d9ae1604350801cd8dc33ebe29fe8aTimo Sirainen mailbox_set_index_error(t->box);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen ret = -1;
8828d7a1e76b7d301bcd7385aa27c52512e855ceTimo Sirainen } else {
8828d7a1e76b7d301bcd7385aa27c52512e855ceTimo Sirainen t->changes->changes_mask = result_r->changes_mask;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen }
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen if (t->save_ctx != NULL) {
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen i_assert(t->save_ctx->dest_mail == NULL);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen t->box->v.transaction_save_commit_post(t->save_ctx, result_r);
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen }
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen if (pvt_sync_ctx != NULL) {
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen if (index_mailbox_sync_pvt_newmails(pvt_sync_ctx, t) < 0) {
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen /* failed to add private flags. a bit too late to
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen return failure though, so just ignore silently */
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen }
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen index_mailbox_sync_pvt_deinit(&pvt_sync_ctx);
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen }
e2d268e9531227ead6a98466ecf3c046c857ef70Timo Sirainen
103b44c67f38862d1e72c9bfdf11f067b4670675Timo Sirainen if (ret < 0)
103b44c67f38862d1e72c9bfdf11f067b4670675Timo Sirainen mail_index_set_error_nolog(t->box->index, mailbox_get_last_error(t->box, NULL));
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen index_transaction_free(t);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return ret;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenstatic void
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenindex_transaction_index_rollback(struct mail_index_transaction *index_trans)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen{
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mailbox_transaction_context *t =
c51390c3ae6e373e7b4a052a94e8e4065b98321cAki Tuomi MAIL_STORAGE_CONTEXT_REQUIRE(index_trans);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
acfeae4e2b5c2acdab88a1377ff6cd4a9b5f0a3aTimo Sirainen if (t->attr_pvt_trans != NULL)
acfeae4e2b5c2acdab88a1377ff6cd4a9b5f0a3aTimo Sirainen dict_transaction_rollback(&t->attr_pvt_trans);
acfeae4e2b5c2acdab88a1377ff6cd4a9b5f0a3aTimo Sirainen if (t->attr_shared_trans != NULL)
acfeae4e2b5c2acdab88a1377ff6cd4a9b5f0a3aTimo Sirainen dict_transaction_rollback(&t->attr_shared_trans);
acfeae4e2b5c2acdab88a1377ff6cd4a9b5f0a3aTimo Sirainen
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen if (t->save_ctx != NULL) {
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen mailbox_save_context_deinit(t->save_ctx);
1460ef7a18c53216ddb4a94bb62fba96076aae8eTimo Sirainen t->box->v.transaction_save_rollback(t->save_ctx);
897368f75a68f97e172ba76540759a10c557f1c3Timo Sirainen }
01937f71b3ae0d5b30b813372f44a3e7e86c89dcTimo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen i_assert(t->mail_ref_count == 0);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen t->super.rollback(index_trans);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen index_transaction_free(t);
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen}
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainenstatic enum mail_index_transaction_flags
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainenindex_transaction_flags_get(enum mailbox_transaction_flags flags)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen{
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen enum mail_index_transaction_flags itrans_flags;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags = MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if ((flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags |= MAIL_INDEX_TRANSACTION_FLAG_HIDE;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if ((flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags |= MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if ((flags & MAILBOX_TRANSACTION_FLAG_SYNC) != 0)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags |= MAIL_INDEX_TRANSACTION_FLAG_SYNC;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen return itrans_flags;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen}
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainenvoid index_transaction_init_pvt(struct mailbox_transaction_context *t)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen{
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen enum mail_index_transaction_flags itrans_flags;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if (t->box->view_pvt == NULL || t->itrans_pvt != NULL)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen return;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags = index_transaction_flags_get(t->flags);
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen t->itrans_pvt = mail_index_transaction_begin(t->box->view_pvt,
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags);
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen t->view_pvt = mail_index_transaction_open_updated_view(t->itrans_pvt);
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen}
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainenvoid index_transaction_init(struct mailbox_transaction_context *t,
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen struct mailbox *box,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi enum mailbox_transaction_flags flags,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi const char *reason)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen{
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen enum mail_index_transaction_flags itrans_flags;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
a341c4cdbd4b93ba479f465ad3f569dc82f57312Timo Sirainen i_assert(box->opened);
013e3b3942e9550fde619a0b3ce6bdd04edc4268Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen itrans_flags = index_transaction_flags_get(flags);
9293bf90039454f47e94e4ba3722a775cfa7d25cTimo Sirainen if ((flags & MAILBOX_TRANSACTION_FLAG_REFRESH) != 0)
b66d803de86bfb411165b3465b0d9ef64ecfe2a1Timo Sirainen mail_index_refresh(box->index);
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
6c2e7ad9c45936aa07cbc9daadf168c362f34a77Timo Sirainen t->flags = flags;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen t->box = box;
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi t->reason = i_strdup(reason);
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen t->itrans = mail_index_transaction_begin(box->view, itrans_flags);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen t->view = mail_index_transaction_open_updated_view(t->itrans);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen array_create(&t->module_contexts, default_pool,
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen sizeof(void *), 5);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen t->cache_view = mail_cache_view_open(box->cache, t->view);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen t->cache_trans = mail_cache_get_transaction(t->cache_view, t->itrans);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
ab9a91eb05a54f7675e0bf861aca53f417e1980dTimo Sirainen if ((flags & MAILBOX_TRANSACTION_FLAG_NO_CACHE_DEC) != 0)
ab9a91eb05a54f7675e0bf861aca53f417e1980dTimo Sirainen mail_cache_view_update_cache_decisions(t->cache_view, FALSE);
ab9a91eb05a54f7675e0bf861aca53f417e1980dTimo Sirainen
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen /* set up after mail_cache_get_transaction(), so that we'll still
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen have the cache_trans available in _index_commit() */
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen t->super = t->itrans->v;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen t->itrans->v.commit = index_transaction_index_commit;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen t->itrans->v.rollback = index_transaction_index_rollback;
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen MODULE_CONTEXT_SET(t->itrans, mail_storage_mail_index_module, t);
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen}
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainenstruct mailbox_transaction_context *
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainenindex_transaction_begin(struct mailbox *box,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi enum mailbox_transaction_flags flags,
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi const char *reason)
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen{
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen struct mailbox_transaction_context *t;
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen t = i_new(struct mailbox_transaction_context, 1);
c6ce2e251ac75fa650c7fbfa52150eae69386293Martti Rannanjärvi index_transaction_init(t, box, flags, reason);
c04f9a724a7b3cc649485a61b0a540868d25d71bTimo Sirainen return t;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen}
4d2211dac61c615c5bdfd501ea54d46c89d41b0fTimo Sirainen
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenint index_transaction_commit(struct mailbox_transaction_context *t,
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen struct mail_transaction_commit_changes *changes_r)
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen{
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen struct mailbox *box = t->box;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen struct mail_index_transaction *itrans = t->itrans;
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen struct mail_index_transaction_commit_result result;
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen int ret = 0;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(changes_r);
6d931bbce16786df431e9ae8201a78a95084316dTimo Sirainen changes_r->pool = pool_alloconly_create(MEMPOOL_GROWING
6d931bbce16786df431e9ae8201a78a95084316dTimo Sirainen "transaction changes", 512);
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen p_array_init(&changes_r->saved_uids, changes_r->pool, 32);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen t->changes = changes_r;
4d2211dac61c615c5bdfd501ea54d46c89d41b0fTimo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if (t->itrans_pvt != NULL)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen ret = mail_index_transaction_commit(&t->itrans_pvt);
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if (mail_index_transaction_commit_full(&itrans, &result) < 0)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen ret = -1;
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen t = NULL;
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen if (ret < 0 && mail_index_is_deleted(box->index))
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen mailbox_set_deleted(box);
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen
9f19a50d5966643c4d1c5ca06868ac2ad31bc4d5Timo Sirainen changes_r->ignored_modseq_changes = result.ignored_modseq_changes;
741d705983e10046f07ef372b760bcdd169b068aTimo Sirainen return ret;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen}
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenvoid index_transaction_rollback(struct mailbox_transaction_context *t)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen{
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen struct mail_index_transaction *itrans = t->itrans;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen if (t->itrans_pvt != NULL)
5da1aa5197a43d83f0fb3eeb83125c7cd73d1b62Timo Sirainen mail_index_transaction_rollback(&t->itrans_pvt);
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen mail_index_transaction_rollback(&itrans);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}