Lines Matching refs:ctx

31 	struct dbox_save_context ctx;
47 #define MDBOX_SAVECTX(s) container_of(DBOX_SAVECTX(s), struct mdbox_save_context, ctx)
53 struct mdbox_save_context *ctx = MDBOX_SAVECTX(t->save_ctx);
58 mail_index_lookup_ext(t->view, seq, ctx->mbox->ext_id, &data, NULL);
61 if (mdbox_map_lookup(ctx->mbox->storage->map, rec->map_uid,
65 return mdbox_file_init(ctx->mbox->storage, file_id);
72 struct mdbox_save_context *ctx = MDBOX_SAVECTX(t->save_ctx);
76 mails = array_get(&ctx->mails, &count);
91 ctx->ctx.failed = TRUE;
102 struct mdbox_save_context *ctx = MDBOX_SAVECTX(t->save_ctx);
106 if (ctx != NULL) {
108 ctx->cur_file = NULL;
109 ctx->ctx.failed = FALSE;
110 ctx->ctx.finished = FALSE;
111 ctx->ctx.dbox_output = NULL;
112 ctx->cur_file_append = NULL;
113 return &ctx->ctx.ctx;
116 ctx = i_new(struct mdbox_save_context, 1);
117 ctx->ctx.ctx.transaction = t;
118 ctx->ctx.trans = t->itrans;
119 ctx->mbox = mbox;
120 ctx->atomic = mdbox_map_atomic_begin(mbox->storage->map);
121 ctx->append_ctx = mdbox_map_append_begin(ctx->atomic);
122 i_array_init(&ctx->mails, 32);
123 t->save_ctx = &ctx->ctx.ctx;
129 struct mdbox_save_context *ctx = MDBOX_SAVECTX(_ctx);
142 if (mdbox_map_append_next(ctx->append_ctx, mail_size, 0,
143 &ctx->cur_file_append,
144 &ctx->ctx.dbox_output) < 0) {
145 ctx->ctx.failed = TRUE;
148 i_assert(ctx->ctx.dbox_output->offset <= (uint32_t)-1);
149 append_offset = ctx->ctx.dbox_output->offset;
151 ctx->cur_file = ctx->cur_file_append->file;
152 dbox_save_begin(&ctx->ctx, input);
154 save_mail = array_append_space(&ctx->mails);
155 save_mail->file_append = ctx->cur_file_append;
156 save_mail->seq = ctx->ctx.seq;
158 return ctx->ctx.failed ? -1 : 0;
161 static int mdbox_save_mail_write_metadata(struct mdbox_save_context *ctx,
171 message_size = ctx->ctx.dbox_output->offset -
174 dbox_save_write_metadata(&ctx->ctx.ctx, ctx->ctx.dbox_output,
175 message_size, ctx->mbox->box.name, guid_128);
178 mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
179 ctx->mbox->guid_ext_id, guid_128, NULL);
182 if (o_stream_pwrite(ctx->ctx.dbox_output, &dbox_msg_hdr,
193 struct mdbox_save_context *ctx = (struct mdbox_save_context *)_ctx;
196 ctx->ctx.finished = TRUE;
197 if (ctx->ctx.dbox_output == NULL)
200 dbox_save_end(&ctx->ctx);
202 mail = array_idx_modifiable(&ctx->mails, array_count(&ctx->mails) - 1);
203 if (!ctx->ctx.failed) T_BEGIN {
204 if (mdbox_save_mail_write_metadata(ctx, mail) < 0)
205 ctx->ctx.failed = TRUE;
207 mdbox_map_append_finish(ctx->append_ctx);
215 i_stream_unref(&ctx->ctx.input);
217 if (ctx->ctx.failed) {
218 index_storage_save_abort_last(&ctx->ctx.ctx, ctx->ctx.seq);
219 mdbox_map_append_abort(ctx->append_ctx);
220 array_delete(&ctx->mails, array_count(&ctx->mails) - 1, 1);
226 int mdbox_save_finish(struct mail_save_context *ctx)
230 ret = mdbox_save_finish_write(ctx);
231 index_save_context_free(ctx);
237 struct dbox_save_context *ctx = DBOX_SAVECTX(_ctx);
239 ctx->failed = TRUE;
244 mdbox_save_set_map_uids(struct mdbox_save_context *ctx,
247 struct mdbox_mailbox *mbox = ctx->mbox;
248 struct mail_index_view *view = ctx->ctx.ctx.transaction->view;
256 mdbox_update_header(mbox, ctx->ctx.trans, NULL);
260 mails = array_get(&ctx->mails, &count);
271 mail_index_update_ext(ctx->ctx.trans, mails[i].seq,
279 struct mdbox_save_context *ctx = MDBOX_SAVECTX(_ctx);
284 i_assert(ctx->ctx.finished);
287 if (mdbox_map_append_flush(ctx->append_ctx) < 0) {
293 if (mdbox_map_atomic_lock(ctx->atomic, "saving") < 0) {
300 if (mdbox_sync_begin(ctx->mbox, MDBOX_SYNC_FLAG_NO_PURGE |
303 MDBOX_SYNC_FLAG_NO_REBUILD, ctx->atomic,
304 &ctx->sync_ctx) < 0) {
313 if (mdbox_map_append_assign_map_uids(ctx->append_ctx, &first_map_uid,
320 dbox_save_update_header_flags(&ctx->ctx, ctx->sync_ctx->sync_view,
321 ctx->mbox->hdr_ext_id, offsetof(struct mdbox_index_header, flags));
324 hdr = mail_index_get_header(ctx->sync_ctx->sync_view);
325 mail_index_append_finish_uids(ctx->ctx.trans, hdr->next_uid,
328 if (ctx->ctx.highest_pop3_uidl_seq != 0) {
334 mails = array_idx(&ctx->mails, 0);
336 ctx->ctx.highest_pop3_uidl_seq - mails[0].seq;
337 i_assert(mails[highest_pop3_uidl_idx].seq == ctx->ctx.highest_pop3_uidl_seq);
342 index_pop3_uidl_set_max_uid(&ctx->mbox->box, ctx->ctx.trans, uid);
347 mdbox_save_set_map_uids(ctx, first_map_uid, last_map_uid);
350 if (array_is_created(&ctx->copy_map_uids)) {
351 ctx->map_trans = mdbox_map_transaction_begin(ctx->atomic, FALSE);
352 if (mdbox_map_update_refcounts(ctx->map_trans,
353 &ctx->copy_map_uids, 1) < 0) {
357 mail_index_sync_set_reason(ctx->sync_ctx->index_sync_ctx, "copying");
359 mail_index_sync_set_reason(ctx->sync_ctx->index_sync_ctx, "saving");
369 struct mdbox_save_context *ctx = MDBOX_SAVECTX(_ctx);
374 mail_index_sync_set_commit_result(ctx->sync_ctx->index_sync_ctx,
378 if (mdbox_sync_finish(&ctx->sync_ctx, TRUE) == 0) {
380 if (ctx->map_trans != NULL) {
381 if (mdbox_map_transaction_commit(ctx->map_trans, "copy refcount updates") < 0)
382 mdbox_map_atomic_set_failed(ctx->atomic);
385 if (mdbox_map_append_commit(ctx->append_ctx) < 0)
386 mdbox_map_atomic_set_failed(ctx->atomic);
388 mdbox_map_append_free(&ctx->append_ctx);
391 (void)mdbox_map_atomic_finish(&ctx->atomic);
394 const char *box_path = mailbox_get_path(&ctx->mbox->box);
406 struct mdbox_save_context *ctx = MDBOX_SAVECTX(_ctx);
408 if (!ctx->ctx.finished)
409 mdbox_save_cancel(&ctx->ctx.ctx);
410 if (ctx->append_ctx != NULL)
411 mdbox_map_append_free(&ctx->append_ctx);
412 if (ctx->map_trans != NULL)
413 mdbox_map_transaction_free(&ctx->map_trans);
414 if (ctx->atomic != NULL)
415 (void)mdbox_map_atomic_finish(&ctx->atomic);
416 if (array_is_created(&ctx->copy_map_uids))
417 array_free(&ctx->copy_map_uids);
419 if (ctx->sync_ctx != NULL)
420 (void)mdbox_sync_finish(&ctx->sync_ctx, FALSE);
422 array_free(&ctx->mails);
423 i_free(ctx);
428 struct mdbox_save_context *ctx = MDBOX_SAVECTX(_ctx);
435 ctx->ctx.finished = TRUE;
465 if (!array_is_created(&ctx->copy_map_uids))
466 i_array_init(&ctx->copy_map_uids, 32);
467 array_append(&ctx->copy_map_uids, &rec.map_uid, 1);
470 dbox_save_add_to_index(&ctx->ctx);
471 mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
472 ctx->mbox->ext_id, &rec, NULL);
474 mail_index_update_ext(ctx->ctx.trans, ctx->ctx.seq,
475 ctx->mbox->guid_ext_id, guid_data, NULL);
476 index_copy_cache_fields(_ctx, mail, ctx->ctx.seq);
478 save_mail = array_append_space(&ctx->mails);
479 save_mail->seq = ctx->ctx.seq;
481 mail_set_seq_saving(_ctx->dest_mail, ctx->ctx.seq);