mail-transaction-log-append.c revision a942db367328a91e3a0b6c810bb8abbcb7663707
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "buffer.h"
#include "write-full.h"
#include "mail-index-private.h"
#include "mail-index-view-private.h"
#include "mail-index-transaction-private.h"
#include "mail-transaction-log-private.h"
{
struct mail_transaction_header hdr;
if (size == 0)
return 0;
} else {
hdr_data_size = 0;
}
if (type == MAIL_TRANSACTION_EXPUNGE)
if (external)
if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
do {
if (file->first_append_size == 0) {
/* size will be written later once everything
is in disk */
} else {
}
offset) < 0)
break;
if (hdr_data_size > 0) {
hdr_data_size, offset) < 0)
break;
offset += hdr_data_size;
}
break;
return 0;
} while (0);
/* write failure. */
"pwrite_full()");
return -1;
/* not enough space. fallback to in-memory indexes. */
return -1;
}
file->sync_offset);
return 0;
}
static const buffer_t *
{
struct mail_transaction_header_update u;
int state = 0;
memset(&u, 0, sizeof(u));
if (state == 0) {
state++;
}
} else {
if (state > 0) {
buffer_append(buf, &u, sizeof(u));
state = 0;
}
}
}
return buf;
}
struct mail_index_transaction *t,
{
const struct mail_index_registered_ext *rext;
struct mail_transaction_ext_intro *intro;
unsigned int count;
/* new extension */
}
if (!array_is_created(&t->ext_resizes)) {
count = 0;
} else {
}
/* we're resizing it */
} else {
/* generate a new intro structure */
}
if (reset_id != 0) {
/* we're going to reset this extension in this transaction */
/* use the existing reset_id */
const struct mail_index_ext *map_ext =
} else {
/* new extension, reset_id defaults to 0 */
}
t->external);
}
static int
struct mail_index_transaction *t)
{
const struct mail_transaction_ext_intro *resize;
struct mail_transaction_ext_reset ext_reset;
if (!array_is_created(&t->ext_rec_updates)) {
update_count = 0;
} else {
}
if (!array_is_created(&t->ext_resizes)) {
resize_count = 0;
} else {
}
if (!array_is_created(&t->ext_resets)) {
reset_count = 0;
} else {
}
(ext_id < update_count &&
ext_reset.new_reset_id != 0) {
return -1;
}
if (ext_reset.new_reset_id != 0) {
t->external) < 0)
return -1;
}
}
return 0;
}
struct mail_index_transaction *t)
{
if (!array_is_created(&t->ext_rec_updates)) {
count = 0;
} else {
}
if (!array_is_created(&t->ext_resets)) {
reset_count = 0;
} else {
}
continue;
return -1;
t->external) < 0)
return -1;
}
return 0;
}
static int
struct mail_index_transaction *t,
{
if (t->hide_transaction) {
}
}
struct mail_index_transaction *t)
{
const struct mail_index_transaction_keyword_update *updates;
const char *const *keywords;
unsigned int i, count, keywords_count;
for (i = 0; i < count; i++) {
MODIFY_ADD, keywords[i],
return -1;
}
MODIFY_REMOVE, keywords[i],
return -1;
}
}
return 0;
}
static int
{
struct mail_index *index;
struct mail_transaction_log *log;
struct mail_transaction_log_file *file;
struct mail_index_header idx_hdr;
unsigned int old_hidden_syncs_count;
unsigned int lock_id;
int ret;
if (!index->log_locked) {
/* update sync_offset */
(uoff_t)-1) < 0)
return -1;
}
/* we might want to rotate, but check first that everything is
synced in index. */
return -1;
/* we need the latest log_file_*_offsets. It's important to
use this function instead of mail_index_map() as it may
have generated them by reading log files. */
return -1;
}
return -1;
}
}
file->first_append_size = 0;
ret = 0;
/* send all extension introductions and resizes before appends
to avoid resize overhead as much as possible */
if (t->pre_hdr_changed && ret == 0) {
t->external);
}
if (t->hide_transaction) {
}
}
if (t->hide_transaction) {
}
t->external);
}
/* keyword resets before updates */
if (t->hide_transaction) {
}
t->external);
}
/* Expunges cannot be hidden */
}
if (t->post_hdr_changed && ret == 0) {
t->external);
}
if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
/* synced - rewrite first record's header */
sizeof(uint32_t), append_offset);
if (ret < 0) {
}
} else {
/* changed into in-memory buffer in the middle */
sizeof(file->first_append_size));
}
}
if (ret < 0) {
/* revert changes to log_syncs */
}
}
return ret;
}
int mail_transaction_log_append(struct mail_index_transaction *t,
{
struct mail_index *index;
int ret;
if (!t->log_updates) {
/* nothing to append */
*log_file_seq_r = 0;
*log_file_offset_r = 0;
return 0;
}
if (index->log_locked) {
} else {
return -1;
}
if (!index->log_locked)
return ret;
}