Lines Matching refs:sync_ctx
15 int mbox_move(struct mbox_sync_context *sync_ctx,
18 struct mbox_mailbox *mbox = sync_ctx->mbox;
29 i_stream_sync(sync_ctx->input);
31 output = o_stream_create_fd_file(sync_ctx->write_fd, (uoff_t)-1, FALSE);
32 i_stream_seek(sync_ctx->file_input, source);
34 mbox_set_syscall_error(sync_ctx->mbox,
42 input = i_stream_create_limit(sync_ctx->file_input, size);
55 mbox_sync_set_critical(sync_ctx,
65 mbox_sync_file_updated(sync_ctx, FALSE);
70 static int mbox_fill_space(struct mbox_sync_context *sync_ctx,
77 if (pwrite_full(sync_ctx->write_fd, space,
79 mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
85 if (pwrite_full(sync_ctx->write_fd, space, size, offset) < 0) {
86 mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
89 mbox_sync_file_updated(sync_ctx, TRUE);
240 ctx->sync_ctx->base_uid_last_offset = hdr_offset +
247 ctx->sync_ctx->base_uid_last = ctx->last_uid_updated_value;
253 struct mbox_sync_context *sync_ctx = ctx->sync_ctx;
256 i_assert(sync_ctx->mbox->mbox_lock_type == F_WRLCK);
279 i_assert(sync_ctx->expunged_space >=
281 sync_ctx->expunged_space -= new_hdr_size - old_hdr_size;
309 if (pwrite_full(sync_ctx->write_fd,
314 mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
318 if (sync_ctx->dest_first_mail &&
319 (ctx->imapbase_updated || ctx->sync_ctx->base_uid_last != 0)) {
325 mbox_sync_file_updated(sync_ctx, FALSE);
329 static int mbox_sync_read_next(struct mbox_sync_context *sync_ctx,
339 mail_ctx->sync_ctx = sync_ctx;
341 mail_ctx->header = sync_ctx->header;
343 if (istream_raw_mbox_get_header_offset(sync_ctx->input,
345 mbox_sync_set_critical(sync_ctx,
351 orig_next_uid = sync_ctx->next_uid;
356 sync_ctx->next_uid = mails[idx].uid;
357 sync_ctx->prev_msg_uid = mails[idx].uid - 1;
361 sync_ctx->prev_msg_uid = 0;
365 (sync_ctx->first_mail_crlf_expunged ? 1 : 0);
368 sync_ctx->dest_first_mail = mails[idx].from_offset == 0;
372 sync_ctx->dest_first_mail = TRUE;
376 if (mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx) < 0)
383 sync_ctx->next_uid = orig_next_uid;
400 static int mbox_sync_read_and_move(struct mbox_sync_context *sync_ctx,
412 if (mbox_sync_seek(sync_ctx, mails[idx].from_offset) < 0)
415 if (mbox_sync_read_next(sync_ctx, &new_mail_ctx, mails, seq, idx,
423 i_stream_seek(sync_ctx->input, mail_ctx->body_offset);
432 mbox_sync_file_update_ext_modified(sync_ctx);
434 mbox_sync_set_critical(sync_ctx,
448 if (mbox_move(sync_ctx, mails[idx].from_offset - expunged_space,
466 offset = sync_ctx->input->v_offset;
469 if (mbox_move(sync_ctx, dest_offset, offset, end_offset - offset) < 0)
477 if (pwrite_full(sync_ctx->write_fd, str_data(mail_ctx->header),
479 mbox_set_syscall_error(sync_ctx->mbox, "pwrite_full()");
482 mbox_sync_file_updated(sync_ctx, TRUE);
484 if (sync_ctx->dest_first_mail) {
486 sync_ctx->dest_first_mail = FALSE;
495 int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx,
509 i_assert(sync_ctx->mbox->mbox_lock_type == F_WRLCK);
511 mails = array_get_modifiable(&sync_ctx->mails, &count);
534 orig_prev_msg_uid = sync_ctx->prev_msg_uid;
556 if (mbox_sync_read_and_move(sync_ctx, mail_ctx, mails,
578 if (mbox_move(sync_ctx, dest_offset, offset,
589 if (mbox_fill_space(sync_ctx, move_diff +
612 mbox_sync_file_updated(sync_ctx, FALSE);
613 sync_ctx->prev_msg_uid = orig_prev_msg_uid;