mail-index-sync.c revision df4018ae2f0a95be602f724ca70df7e0e3bd6a7d
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "mail-index-view-private.h"
#include "mail-index-sync-private.h"
#include "mail-transaction-log.h"
#include "mail-transaction-util.h"
#include "mail-cache.h"
#include <stdlib.h>
static void
const struct mail_transaction_flag_update *src,
{
const struct mail_transaction_flag_update *src_end;
struct mail_transaction_flag_update *dest;
size_t i, dest_count;
int j;
dest_count /= sizeof(*dest);
if (dest_count == 0) {
return;
}
new_update = *src;
/* insert it into buffer, split and merge it with existing
updates if needed. */
for (; i < dest_count; i++) {
continue;
break;
/* at least partially overlapping */
/* { 5..6 } + { 1..5 } -> { 1..4 } + { 5..6 } */
&tmp_update, sizeof(tmp_update));
NULL);
dest_count++; i++;
/* { 5..7 } + { 6..6 } ->
split old to { 5..5 } + { 6..7 } */
tmp_update = dest[i];
&tmp_update, sizeof(tmp_update));
NULL);
dest_count++; i++;
}
/* { 5..7 } + { 5..6 } -> { 5..6 } + { 7..7 } */
tmp_update = dest[i];
(i+1) * sizeof(tmp_update),
&tmp_update, sizeof(tmp_update));
NULL);
dest_count++;
new_update.uid2 = 0;
} else {
/* full match, or continues. */
}
/* dest[i] now contains the overlapping area.
merge them - new_update overrides old changes. */
for (j = 0; j < INDEX_KEYWORDS_BYTE_COUNT; j++) {
dest[i].add_keywords[j] |=
dest[i].add_keywords[j] &=
dest[i].remove_keywords[j] |=
dest[i].remove_keywords[j] &=
~new_update.add_keywords[j];
}
}
&new_update, sizeof(new_update));
dest_count++;
}
}
}
{
case MAIL_TRANSACTION_EXPUNGE:
break;
break;
case MAIL_TRANSACTION_APPEND: {
if (ctx->append_uid_first == 0 ||
break;
}
}
}
{
struct mail_transaction_flag_update update;
const struct mail_index_record *rec;
int i;
return -1;
continue;
for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
}
return 0;
}
{
struct mail_transaction_flag_update update;
const struct mail_index_record *rec;
return -1;
&update,
sizeof(update));
}
continue;
}
/* group updates together as much as possible */
}
}
return 0;
}
static int
int *seen_external_r)
{
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 (sync_recent) {
if (mail_index_sync_add_recent_updates(ctx) < 0)
return -1;
}
*seen_external_r = TRUE;
else
}
return ret;
}
{
return 1;
/* already synced */
}
return 1;
}
{
int ret;
NULL)) > 0) {
break;
}
if (ret < 0)
return -1;
if (ret > 0) {
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,
int sync_recent, int sync_dirty)
{
struct mail_index_sync_ctx *ctx;
unsigned int lock_id = 0;
int 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;
}
}
return 0;
}
MAIL_TRANSACTION_TYPE_MASK) < 0) {
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. */
return -1;
}
MAIL_TRANSACTION_TYPE_MASK) < 0) {
return -1;
}
}
/* we need to have all the transactions sorted to optimize
caller's mailbox access patterns */
&seen_external) < 0) {
return -1;
}
return 1;
}
void
const struct mail_transaction_expunge *exp)
{
}
void
const struct mail_transaction_flag_update *update)
{
sizeof(rec->add_keywords));
sizeof(rec->remove_keywords));
}
struct mail_index_sync_rec *rec)
{
"Broken UID range: %u..%u (type 0x%x)",
return FALSE;
}
break;
break;
}
return TRUE;
}
struct mail_index_sync_rec *sync_rec)
{
const struct mail_transaction_expunge *next_exp;
const struct mail_transaction_flag_update *next_update;
if (next_update != NULL &&
/* it's overlapping with next expunge */
}
/* overlapping with previous expunge */
/* hide this update completely */
ctx->update_idx++;
}
}
ctx->update_idx++;
}
return -1;
ctx->expunge_idx++;
return 1;
}
if (ctx->sync_appends) {
return 1;
}
return 0;
}
{
}
{
}
{
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. */
ret = -1;
ret = -1;
}
ret = -1;
else {
/* cache_offsets have changed, sync them */
ret = -1;
ret = -1;
}
}
return ret;
}
{
}
{
int i;
for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
sync_rec->add_keywords[i];
}
}