mail-index-sync.c revision ec255ec6967f1bfd9811a58c0388a09f98dbef6b
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "buffer.h"
#include "mail-index-view-private.h"
#include "mail-index-sync-private.h"
#include "mail-index-transaction-private.h"
#include "mail-transaction-log-private.h"
#include "mail-transaction-util.h"
#include "mail-cache.h"
#include <stdlib.h>
struct uid_range {
};
{
for (i = 0; i < size; i++) {
}
}
{
for (i = 0; i < size; i++) {
if (u[i].add_flags != 0) {
u[i].add_flags);
}
if (u[i].remove_flags != 0) {
u[i].remove_flags);
}
}
}
{
const char *keyword_names[2];
struct mail_keywords *keywords;
uidset_offset = sizeof(*u) + u->name_size;
if ((uidset_offset % 4) != 0)
t_push();
for (i = 0; i < size; i += 2) {
/* FIXME: mail_index_update_keywords_range() */
u->modify_type, keywords);
}
}
t_pop();
}
{
struct mail_keywords *keywords;
for (i = 0; i < size; i++) {
}
}
}
{
}
{
case MAIL_TRANSACTION_EXPUNGE:
break;
break;
break;
break;
case MAIL_TRANSACTION_APPEND:
break;
}
}
{
struct mail_transaction_flag_update update;
const struct mail_index_record *rec;
return -1;
continue;
}
return 0;
}
{
const struct mail_index_record *rec;
bool seen_recent = FALSE;
return -1;
seen_recent = TRUE;
}
}
if (!seen_recent) {
/* no recent messages, drop the sync_recent flag so we
don't scan through the message again */
}
return 0;
}
static int
bool *seen_external_r)
{
struct mail_index_sync_list *synclist;
const struct mail_index_transaction_keyword_update *keyword_updates;
unsigned int i, keyword_count;
int ret;
*seen_external_r = FALSE;
ctx->sync_dirty) {
/* show dirty flags as flag updates */
if (mail_index_sync_add_dirty_updates(ctx) < 0)
return -1;
}
if (ctx->sync_recent) {
if (mail_index_sync_add_recent_updates(ctx) < 0)
return -1;
}
/* read all transactions from log into a transaction in memory */
*seen_external_r = TRUE;
else
}
/* create an array containing all expunge, flag and keyword update
arrays so we can easily go through all of the changes. */
}
}
/* we must return resets before keyword additions or they get lost */
}
for (i = 0; i < keyword_count; i++) {
synclist->keyword_idx = i;
}
synclist->keyword_idx = i;
}
}
return ret;
}
{
return 1;
/* already synced */
}
return 1;
}
static int
{
int ret;
if (ret <= 0) {
/* either corrupted or the file was deleted for
some reason. either way, we can't go forward */
"Unexpected transaction log desync with index %s",
return -1;
}
return 0;
}
{
int ret;
/* find the first external transaction, if there are any */
NULL)) > 0) {
break;
}
if (ret < 0)
return -1;
if (ret > 0) {
/* found it. update log view's range to begin from it and
write all external transactions to index. */
return -1;
return -1;
}
return 0;
}
#define MAIL_INDEX_IS_SYNCS_SAME(index) \
struct mail_index_sync_ctx **ctx_r,
struct mail_index_view **view_r,
bool sync_recent, bool sync_dirty)
{
struct mail_index_sync_ctx *ctx;
struct mail_index_view *dummy_view;
unsigned int lock_id = 0;
bool seen_external;
return -1;
/* make sure we have the latest file mapped */
return -1;
}
/* with mmap_disable the force parameter has somewhat special
file's header. */
return -1;
}
}
if (mail_index_fsck(index) <= 0) {
return -1;
}
}
return 0;
}
/* broken sync positions. fix them. */
if (mail_index_fsck(index) <= 0) {
return -1;
}
}
return -1;
}
/* See if there are some external transactions which were
written to transaction log, but weren't yet committed to
index. commit them first to avoid conflicts with another
external sync.
This is mostly needed to make sure there won't be multiple
appends with same UIDs, because those would cause
transaction log to be marked corrupted.
Note that any internal transactions must not be committed
yet. They need to be synced with the real mailbox first. */
if (mail_index_sync_commit_external(ctx) < 0) {
return -1;
}
return -1;
}
/* we need to have all the transactions sorted to optimize
caller's mailbox access patterns */
return -1;
}
return 1;
}
static void
const struct mail_transaction_expunge *exp)
{
}
static void
const struct mail_transaction_flag_update *update)
{
}
static void
struct mail_index_sync_list *sync_list)
{
}
{
}
struct mail_index_sync_rec *rec)
{
"Broken UID range: %u..%u (type 0x%x)",
return -1;
}
break;
break;
}
return 0;
}
struct mail_index_sync_rec *sync_rec)
{
struct mail_index_sync_list *sync_list;
next_i = (unsigned int)-1;
/* FIXME: replace with a priority queue so we don't have to go
through the whole list constantly. and remember to make sure that
keyword resets are sent before adds! */
for (i = 0; i < count; i++) {
continue;
/* use this one. */
break;
}
next_i = i;
}
}
if (i == count) {
if (next_i == (unsigned int)-1) {
/* nothing left in sync_list */
if (ctx->sync_appends) {
return 1;
}
return 0;
}
i = next_i;
}
(const struct mail_transaction_expunge *)uid_range);
(const struct mail_transaction_flag_update *)uid_range);
} else {
&sync_list[i]);
}
return -1;
return 1;
}
{
const struct mail_index_sync_list *sync_list;
unsigned int i, count;
if (ctx->sync_appends)
return TRUE;
for (i = 0; i < count; i++) {
return TRUE;
}
return FALSE;
}
{
struct mail_index_sync_list *sync_list;
unsigned int i, count;
for (i = 0; i < count; i++)
}
{
}
{
const struct mail_index_header *hdr;
int ret = 0;
ret = -1;
/* we have had the transaction log locked since the beginning of sync,
so only external changes could have been committed. write them to
the index here as well. */
ctx->sync_recent)) {
/* write all pending changes to index. */
hdr->log_file_int_offset) < 0)
ret = -1;
ret = -1;
}
/* if cache compression fails, we don't really care */
/* cache_offsets have changed, sync them */
ret = -1;
ret = -1;
}
}
return ret;
}
{
}
{
}
{
ARRAY_SET_TYPE(keywords, unsigned int);
const unsigned int *keyword_indexes;
unsigned int i, count;
for (i = 0; i < count; i++) {
if (keyword_indexes[i] == idx)
return FALSE;
}
return TRUE;
for (i = 0; i < count; i++) {
if (keyword_indexes[i] == idx) {
return TRUE;
}
}
return FALSE;
if (array_count(keywords) == 0)
return FALSE;
return TRUE;
default:
i_unreached();
return FALSE;
}
}