summaryrefslogtreecommitdiffstats
path: root/src/plugins/virtual/virtual-transaction.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/plugins/virtual/virtual-transaction.c
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/plugins/virtual/virtual-transaction.c')
-rw-r--r--src/plugins/virtual/virtual-transaction.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/plugins/virtual/virtual-transaction.c b/src/plugins/virtual/virtual-transaction.c
new file mode 100644
index 0000000..53ac0a8
--- /dev/null
+++ b/src/plugins/virtual/virtual-transaction.c
@@ -0,0 +1,87 @@
+/* Copyright (c) 2008-2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "virtual-storage.h"
+#include "virtual-transaction.h"
+
+struct mailbox_transaction_context *
+virtual_transaction_get(struct mailbox_transaction_context *trans,
+ struct mailbox *backend_box)
+{
+ struct virtual_transaction_context *vt =
+ (struct virtual_transaction_context *)trans;
+ struct mailbox_transaction_context *const *bt, *new_bt;
+ unsigned int i, count;
+
+ bt = array_get(&vt->backend_transactions, &count);
+ for (i = 0; i < count; i++) {
+ if (bt[i]->box == backend_box)
+ return bt[i];
+ }
+
+ new_bt = mailbox_transaction_begin(backend_box, trans->flags, __func__);
+ array_push_back(&vt->backend_transactions, &new_bt);
+ return new_bt;
+}
+
+struct mailbox_transaction_context *
+virtual_transaction_begin(struct mailbox *box,
+ enum mailbox_transaction_flags flags,
+ const char *reason)
+{
+ struct virtual_mailbox *mbox = (struct virtual_mailbox *)box;
+ struct virtual_transaction_context *vt;
+
+ vt = i_new(struct virtual_transaction_context, 1);
+ i_array_init(&vt->backend_transactions,
+ array_count(&mbox->backend_boxes));
+ index_transaction_init(&vt->t, box, flags, reason);
+ return &vt->t;
+}
+
+int virtual_transaction_commit(struct mailbox_transaction_context *t,
+ struct mail_transaction_commit_changes *changes_r)
+{
+ struct virtual_transaction_context *vt =
+ (struct virtual_transaction_context *)t;
+ struct mailbox_transaction_context **bt;
+ unsigned int i, count;
+ int ret = 0;
+
+ if (t->save_ctx != NULL) {
+ virtual_save_free(t->save_ctx);
+ t->save_ctx = NULL;
+ }
+
+ bt = array_get_modifiable(&vt->backend_transactions, &count);
+ for (i = 0; i < count; i++) {
+ if (mailbox_transaction_commit(&bt[i]) < 0)
+ ret = -1;
+ }
+ array_free(&vt->backend_transactions);
+
+ if (index_transaction_commit(t, changes_r) < 0)
+ ret = -1;
+ return ret;
+}
+
+void virtual_transaction_rollback(struct mailbox_transaction_context *t)
+{
+ struct virtual_transaction_context *vt =
+ (struct virtual_transaction_context *)t;
+ struct mailbox_transaction_context **bt;
+ unsigned int i, count;
+
+ if (t->save_ctx != NULL) {
+ virtual_save_free(t->save_ctx);
+ t->save_ctx = NULL;
+ }
+
+ bt = array_get_modifiable(&vt->backend_transactions, &count);
+ for (i = 0; i < count; i++)
+ mailbox_transaction_rollback(&bt[i]);
+ array_free(&vt->backend_transactions);
+
+ index_transaction_rollback(t);
+}