dbox-sync.c revision 4b41116563110d00330896a568eff1078c382827
/* Copyright (C) 2005 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "hash.h"
#include "seq-range-array.h"
#include "write-full.h"
#include "dbox-file.h"
#include "dbox-keywords.h"
#include "dbox-sync.h"
#include "dbox-uidlist.h"
#include "dbox-storage.h"
#include <stddef.h>
{
int ret;
if (ret <= 0) {
if (ret == 0) {
"Unexpectedly lost seq %u in "
}
return -1;
}
if (*file_seq_r == 0) {
"Cached message offset lost for seq %u in "
return -1;
}
return 0;
}
const struct dbox_sync_rec *sync_rec)
{
struct dbox_sync_rec new_sync_rec;
struct dbox_sync_file_entry *entry;
unsigned int i, count;
return -1;
for (i = 0; i < count; i++) {
/* already added */
return 0;
}
}
}
new_sync_rec = *sync_rec;
return 0;
}
{
const struct mail_index_record *rec;
return -1;
}
}
return 0;
}
const struct mail_index_sync_rec *sync_rec)
{
struct dbox_sync_rec dbox_sync_rec;
/* don't care about appends */
return 0;
}
return -1;
}
if (seq1 == 0) {
/* already expunged everything. nothing to do. */
return 0;
}
/* convert to dbox_sync_rec, which takes a bit less space and has
sequences instead of UIDs. */
return -1;
}
break;
break;
break;
}
/* now, add the same sync_rec to each file_seq's entry */
return -1;
}
return 0;
}
static int
const struct dbox_sync_rec *sync_rec,
unsigned int first_flag_offset, unsigned int flag_count,
{
enum mailbox_sync_type sync_type;
unsigned int i, start;
int ret;
return -1;
return -1;
}
return ret;
break;
break;
break;
default:
sync_type = 0;
i_unreached();
}
}
for (i = 0; i < flag_count; ) {
if (!mask[i]) {
i++;
continue;
}
start = i;
while (i < flag_count) {
if (!mask[i])
break;
i++;
}
if (ret < 0) {
"pwrite(%s) failed: %m",
return -1;
}
}
if (ret <= 0) {
if (ret == 0)
break;
return -1;
}
}
return 0;
}
const struct dbox_sync_rec *sync_rec)
{
static enum mail_flags dbox_flag_list[] = {
};
unsigned char dbox_flag_array[DBOX_FLAG_COUNT];
unsigned char dbox_flag_mask[DBOX_FLAG_COUNT];
unsigned int i, first_flag_offset;
/* first build flag array and mask */
dbox_flag_array[0] = '1';
dbox_flag_mask[0] = 1;
} else {
for (i = 0; i < DBOX_FLAG_COUNT; i++) {
dbox_flag_array[i] =
dbox_flag_mask[i] =
dbox_flag_list[i]) != 0;
}
}
}
static int
const struct dbox_sync_file_entry *entry,
{
unsigned int file_idx, first_flag_offset;
return -1;
/* not found. if removing, just ignore.
if adding, it currently happens only if the maximum keyword
count was reached. once we support moving mails to new file
to grow keywords count, this should never happen.
for now, just ignore this. */
return 0;
}
}
static int
const struct dbox_sync_file_entry *entry,
const struct dbox_sync_rec *sync_rec)
{
unsigned char *keyword_array, *keyword_mask;
unsigned int first_flag_offset;
int ret;
return -1;
return 0;
t_push();
first_flag_offset = sizeof(struct dbox_mail_header);
t_pop();
return ret;
}
static int
const struct dbox_sync_file_entry *entry,
unsigned int i)
{
const struct dbox_sync_rec *sync_recs;
int ret = 0;
return -1;
/* Get a list of all new keywords. Using seq_range is the easiest
way to do this and should be pretty fast too. */
t_push();
for (; i < count; i++) {
continue;
/* check if it's already in the file */
keyword_idx, &file_idx))
continue;
/* add it. if it already exists, it's handled internally. */
}
/* now, write them to file */
if (count > 0) {
}
t_pop();
return ret;
}
const struct dbox_sync_file_entry *entry)
{
const struct dbox_sync_rec *sync_recs;
unsigned int i, count;
bool first_keyword = TRUE;
int ret;
for (i = 0; i < count; i++) {
t_push();
t_pop();
if (ret > 0) {
/* handled expunging by copying the file.
while at it, also wrote all the other sync
changes to the file. */
return 0;
}
if (ret < 0)
return -1;
/* handled expunging by writing expunge flags */
break;
return -1;
break;
if (first_keyword) {
/* add all new keywords in one go */
i) < 0)
return -1;
}
TRUE) < 0)
return -1;
break;
FALSE) < 0)
return -1;
break;
&sync_recs[i]) < 0)
return -1;
break;
i_unreached();
}
}
return 0;
}
{
struct mail_index_sync_rec sync_rec;
struct hash_iterate_context *iter;
int ret;
/* read all changes and sort them to file_seq order */
for (;;) {
if (ret <= 0) {
if (ret < 0)
break;
}
ret = -1;
break;
}
}
ret = -1;
break;
}
}
return ret;
}
{
const struct mail_index_header *hdr;
int ret;
/* uidlist locking is done before index locking. */
&mtime) < 0)
return -1;
if (ret <= 0) {
if (ret < 0)
return ret;
}
/* indexes aren't synced. we'll do a full sync. */
}
return 1;
}
{
const struct mail_index_header *hdr;
int ret;
if (force)
else
if (ret < 0) {
return -1;
}
}
}
return -1;
}
}
return -1;
}
if (force) {
} else {
return -1;
}
}
return 0;
}
{
struct dbox_sync_context ctx;
int ret;
return ret;
return ret;
if (force) {
/* now that indexes are ok, sync changes from the index */
return ret;
if (force) {
"dbox_sync_full(%s) didn't work",
return -1;
}
} else {
return 0;
}
}
{
int ret;
return ret;
}
struct mailbox_sync_context *
{
int ret = 0;
if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 ||
}
{
const struct mail_index_header *hdr;
if (hdr->sync_stamp == 0)
return 1;
return -1;
}