Example #1
0
static int
index_transaction_index_commit(struct mail_index_transaction *index_trans,
			       struct mail_index_transaction_commit_result *result_r)
{
	struct index_transaction_context *it =
		MAIL_STORAGE_CONTEXT(index_trans);
	struct mailbox_transaction_context *t = &it->mailbox_ctx;
	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(t->box);
	int ret = 0;

	if (t->save_ctx != NULL) {
		if (ibox->save_commit_pre(t->save_ctx) < 0) {
			t->save_ctx = NULL;
			ret = -1;
		}
	}

	i_assert(it->mail_ref_count == 0);
	if (ret < 0)
		it->super.rollback(index_trans);
	else {
		if (it->super.commit(index_trans, result_r) < 0) {
			mail_storage_set_index_error(t->box);
			ret = -1;
		}
	}

	if (t->save_ctx != NULL)
		ibox->save_commit_post(t->save_ctx, result_r);

	index_transaction_free(it);
	return ret;
}
static void
index_transaction_index_rollback(struct mail_index_transaction *index_trans)
{
	struct mailbox_transaction_context *t =
		MAIL_STORAGE_CONTEXT(index_trans);

	if (t->save_ctx != NULL)
		t->box->v.transaction_save_rollback(t->save_ctx);

	i_assert(t->mail_ref_count == 0);
	t->super.rollback(index_trans);
	index_transaction_free(t);
}
Example #3
0
static void index_transaction_index_rollback(struct mail_index_transaction *t)
{
	struct index_transaction_context *it = MAIL_STORAGE_CONTEXT(t);
	struct index_mailbox_context *ibox =
		INDEX_STORAGE_CONTEXT(it->mailbox_ctx.box);

	if (it->mailbox_ctx.save_ctx != NULL)
		ibox->save_rollback(it->mailbox_ctx.save_ctx);

	i_assert(it->mail_ref_count == 0);
	it->super.rollback(t);
	index_transaction_free(it);
}
static int
index_transaction_index_commit(struct mail_index_transaction *index_trans,
			       struct mail_index_transaction_commit_result *result_r)
{
	struct mailbox_transaction_context *t =
		MAIL_STORAGE_CONTEXT(index_trans);
	struct index_mailbox_sync_pvt_context *pvt_sync_ctx = NULL;
	int ret = 0;

	if (t->nontransactional_changes)
		t->changes->changed = TRUE;

	if (t->attr_pvt_trans != NULL) {
		if (dict_transaction_commit(&t->attr_pvt_trans) < 0) {
			mail_storage_set_internal_error(t->box->storage);
			ret = -1;
		}
	}
	if (t->attr_shared_trans != NULL) {
		if (dict_transaction_commit(&t->attr_shared_trans) < 0) {
			mail_storage_set_internal_error(t->box->storage);
			ret = -1;
		}
	}

	if (t->save_ctx != NULL) {
		if (ret < 0) {
			t->box->v.transaction_save_rollback(t->save_ctx);
			t->save_ctx = NULL;
		} else if (t->box->v.transaction_save_commit_pre(t->save_ctx) < 0) {
			t->save_ctx = NULL;
			ret = -1;
		} else {
			t->changes->changed = TRUE;
		}
	}

	if (array_is_created(&t->pvt_saves)) {
		if (index_mailbox_sync_pvt_init(t->box, TRUE, &pvt_sync_ctx) < 0)
			ret = -1;
	}

	i_assert(t->mail_ref_count == 0);
	if (ret < 0)
		t->super.rollback(index_trans);
	else {
		if (t->super.commit(index_trans, result_r) < 0) {
			mailbox_set_index_error(t->box);
			ret = -1;
		} else if (result_r->commit_size > 0) {
			/* something was written to the transaction log */
			t->changes->changed = TRUE;
		}
	}

	if (t->save_ctx != NULL)
		t->box->v.transaction_save_commit_post(t->save_ctx, result_r);

	if (pvt_sync_ctx != NULL) {
		if (index_mailbox_sync_pvt_newmails(pvt_sync_ctx, t) < 0) {
			/* failed to add private flags. a bit too late to
			   return failure though, so just ignore silently */
		}
		index_mailbox_sync_pvt_deinit(&pvt_sync_ctx);
	}

	index_transaction_free(t);
	return ret;
}