dbox-sync.c revision cc977f55ce66b63e8b37c20fce58d0ef516f0f29
/* Copyright (c) 2007-2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "str.h"
#include "hash.h"
#include "dbox-storage.h"
#include "dbox-index.h"
#include "dbox-file.h"
#include "dbox-sync.h"
#define DBOX_REBUILD_COUNT 3
{
struct dbox_sync_file_entry *entry;
bool uid_file;
return -1;
if (type != MAIL_INDEX_SYNC_TYPE_EXPUNGE &&
!ctx->flush_dirty_flags) {
(enum mail_flags)MAIL_INDEX_MAIL_FLAG_DIRTY);
return 0;
}
}
if (type == MAIL_INDEX_SYNC_TYPE_EXPUNGE) {
}
} else {
}
}
return 0;
}
const struct mail_index_sync_rec *sync_rec)
{
/* don't care about appends */
return 0;
}
/* we assume that anything else than appends are interactive changes */
/* already expunged everything. nothing to do. */
return 0;
}
return -1;
}
return 0;
}
static int
{
struct dbox_index_record *rec;
int ret;
&lock_status);
if (ret < 0)
return -1;
switch (lock_status) {
case DBOX_INDEX_FILE_LOCKED:
break;
break;
break;
}
return 0;
}
{
for (i = 0; i < count; i++) {
return -1;
}
}
return 0;
}
{
for (i = 0; i < count; i++) {
}
}
{
struct dbox_index_header hdr;
const void *data;
if (!ctx->flush_dirty_flags) {
/* write the header if it doesn't exist yet */
if (data_size != 0)
return;
}
sizeof(hdr.last_dirty_flush_stamp));
}
{
const struct mail_index_header *hdr;
struct mail_index_sync_rec sync_rec;
struct hash_iterate_context *iter;
int ret = 1;
if (hdr->uid_validity == 0) {
/* newly created index file */
return 0;
}
/* mark the newly seen messages as recent */
}
/* read all changes and sort them to file_id order */
for (;;) {
break;
ret = 0;
break;
}
}
if (ret > 0) {
if (dbox_sync_lock_expunge_files(ctx) < 0)
ret = -1;
}
if (ret > 0) {
/* now sync each file separately */
break;
}
}
if (ret > 0)
return ret;
}
bool close_flush_dirty_flags)
{
const struct dbox_index_header *hdr;
const void *data;
if (mbox->last_interactive_change <
return 1;
/* data_size=0 means it's never been synced as dbox */
if (data_size != 0) {
i_warning("dbox %s: Invalid dbox header size",
}
return -1;
}
if (!close_flush_dirty_flags) {
return 1;
} else {
return 1;
}
return 0;
}
struct dbox_sync_context **ctx_r,
bool close_flush_dirty_flags, bool force)
{
struct dbox_sync_context *ctx;
enum mail_index_sync_flags sync_flags = 0;
unsigned int i;
int ret;
if (ret > 0)
else if (ret < 0)
else {
if (close_flush_dirty_flags) {
/* no need to sync */
return 0;
}
}
(sync_flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0;
/* don't write unnecessary dirty flag updates */
for (i = 0;; i++) {
if (ret <= 0) {
if (ret < 0)
return ret;
}
/* another process rebuilt it already */
}
if (rebuild) {
ret = 0;
} else {
break;
}
/* failure. keep the index locked while we're doing a
rebuild. */
if (ret == 0) {
if (i >= DBOX_REBUILD_COUNT) {
"dbox %s: Index keeps breaking",
ret = -1;
} else {
/* do a full resync and try again. */
}
}
if (ret < 0) {
return -1;
}
}
return 0;
}
{
if (success) {
ret = -1;
}
} else {
}
return 0;
}
{
struct dbox_sync_context *sync_ctx;
close_flush_dirty_flags, FALSE) < 0)
return -1;
return 0;
}
struct mailbox_sync_context *
{
int ret = 0;
}