bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenvoid mail_index_file_set_syscall_error(struct mail_index *index ATTR_UNUSED,
6ded8819b9002150a95a7615e4f64f091c250464Timo Sirainenint mail_transaction_log_lock_head(struct mail_transaction_log *log ATTR_UNUSED,
2f8da04d700cc23fcd6630226a4866e828b761bdTimo Sirainenvoid mail_transaction_log_file_unlock(struct mail_transaction_log_file *file ATTR_UNUSED,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainenvoid mail_transaction_update_modseq(const struct mail_transaction_header *hdr,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen if ((hdr->type & MAIL_TRANSACTION_EXPUNGE) != 0)
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainenint mail_index_move_to_memory(struct mail_index *index ATTR_UNUSED)
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainenstatic void test_append_expunge(struct mail_transaction_log *log)
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen static unsigned int buf[] = { 0x12345678, 0xabcdef09 };
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen struct mail_transaction_log_file *file = log->head;
650441dd8282f8fa6ae58d231c0c34488c3bdb49Timo Sirainen const struct mail_transaction_boundary *bound;
e169102fb38ce788b76c2a344bee7d77079dea05Timo Sirainen test_assert(mail_transaction_log_append_begin(log->index, MAIL_TRANSACTION_EXTERNAL, &ctx) == 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen mail_transaction_log_append_add(ctx, MAIL_TRANSACTION_APPEND,
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen mail_transaction_log_append_add(ctx, MAIL_TRANSACTION_EXPUNGE,
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(mail_transaction_log_append_commit(&ctx) == 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(file->sync_offset == file->buffer_offset + file->buffer->used);
650441dd8282f8fa6ae58d231c0c34488c3bdb49Timo Sirainen test_assert(hdr->type == (MAIL_TRANSACTION_BOUNDARY |
650441dd8282f8fa6ae58d231c0c34488c3bdb49Timo Sirainen test_assert(mail_index_offset_to_uint32(hdr->size) == sizeof(*hdr) + sizeof(*bound));
650441dd8282f8fa6ae58d231c0c34488c3bdb49Timo Sirainen test_assert(bound->size == file->buffer->used);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(hdr->type == (MAIL_TRANSACTION_APPEND |
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(mail_index_offset_to_uint32(hdr->size) == sizeof(*hdr) + sizeof(buf[0]));
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(hdr->type == (MAIL_TRANSACTION_EXPUNGE |
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(mail_index_offset_to_uint32(hdr->size) == sizeof(*hdr) + sizeof(buf[0]));
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(file->buffer->used == (size_t)((const char *)(bufp+1) - (const char *)file->buffer->data));
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainenstatic void test_append_sync_offset(struct mail_transaction_log *log)
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen struct mail_transaction_log_file *file = log->head;
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen const struct mail_transaction_header_update *u;
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_begin("transaction log append: append_sync_offset only");
e169102fb38ce788b76c2a344bee7d77079dea05Timo Sirainen test_assert(mail_transaction_log_append_begin(log->index, 0, &ctx) == 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(mail_transaction_log_append_commit(&ctx) == 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(file->buffer->used == sizeof(*hdr) + sizeof(*u) + sizeof(*offsetp));
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(hdr->type == MAIL_TRANSACTION_HEADER_UPDATE);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(mail_index_offset_to_uint32(hdr->size) == file->buffer->used);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(u->offset == offsetof(struct mail_index_header, log_file_tail_offset));
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainenstatic void test_mail_transaction_log_append(void)
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen log->head = file = i_new(struct mail_transaction_log_file, 1);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_begin("transaction log append: lock failure");
e169102fb38ce788b76c2a344bee7d77079dea05Timo Sirainen test_assert(mail_transaction_log_append_begin(log->index, 0, &ctx) < 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen /* do this after head->buffer has already been initialized */
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_begin("transaction log append: garbage truncation");
e169102fb38ce788b76c2a344bee7d77079dea05Timo Sirainen test_assert(mail_transaction_log_append_begin(log->index, 0, &ctx) == 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen test_assert(mail_transaction_log_append_commit(&ctx) == 0);
5550482ce58e51584f83c10a4c63d35b66431742Timo Sirainen if (fstat(fd, &st) < 0) i_fatal("fstat() failed: %m");
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen static void (*const test_functions[])(void) = {