dbox-sync-file.c revision 4645cc6c911a95991d7af43b40f88e99506ea5e9
/* Copyright (c) 2007 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
#include "dbox-storage.h"
#include "dbox-index.h"
#include "dbox-file.h"
#include "dbox-sync.h"
{
const char *path;
int i;
for (i = 0;; i++) {
break;
"unlink(%s) failed: %m", path);
return -1;
}
/* not found */
i_warning("dbox: File unexpectedly lost: %s/%s",
break;
}
/* try the alternative path */
}
return 0;
}
static void
const struct dbox_sync_file_entry *entry,
{
const struct mail_index_record *rec;
struct mail_keywords *keywords;
const char *old_value;
t_push();
/* flags */
/* keywords */
if (array_count(&keyword_indexes) > 0 ||
array_count(&keyword_indexes) == 0)) {
str_truncate(value, 0);
}
/* expunge state */
}
t_pop();
}
static int
const struct dbox_sync_file_entry *entry)
{
const char *out_path;
unsigned int i, count;
bool expunged;
int ret;
&file_id, &first_offset))
return 0;
for (i = 0;;) {
&physical_size)) <= 0)
break;
if (uid == 0) {
/* EOF */
break;
}
if (i < count) {
if (++i == count)
break;
}
}
/* this message gets expunged */
if (seq != 0)
continue;
}
/* non-expunged message. write it to output file. */
&output);
if (ret <= 0)
break;
}
if (ret < 0)
break;
/* write metadata */
break;
(enum mail_flags)MAIL_INDEX_MAIL_FLAG_DIRTY);
}
if (ret <= 0) {
}
/* FIXME: rename out_file and add to index */
}
if (ret <= 0)
;
/* nothing exists in this file anymore */
} else {
ret = -1;
}
}
return ret;
}
static int
{
struct dbox_index_append_context *append_ctx;
struct dbox_message_header dbox_msg_hdr;
struct dbox_mail_index_record rec;
const char *out_path;
int ret;
bool expunged;
/* FIXME: for now we handle only maildir file conversion */
if (ret <= 0)
return ret;
if (expunged) {
return 1;
}
return -1;
}
/* copy the message */
o_stream_flush(output) < 0) {
"write(%s) failed: %m", out_path);
ret = -1;
} else {
}
if (ret < 0)
else
if (ret == 0) {
/* update message position in index file */
}
/* when everything is done, unlink the old file */
}
}
static int
{
bool expunged;
int ret;
return 0;
if (ret <= 0)
return ret;
if (expunged) {
return 1;
}
if (ret <= 0) {
return ret < 0 ? -1 :
}
(enum mail_flags)MAIL_INDEX_MAIL_FLAG_DIRTY);
return 1;
}
static int
{
unsigned int i, count;
int ret;
} else {
}
for (i = 0; i < count; ) {
if (seq >= first_expunge_seq)
if (ret <= 0)
return ret;
}
i++;
}
return 1;
}
static void
const struct dbox_sync_file_entry *entry)
{
unsigned int count;
}
const struct dbox_sync_file_entry *entry)
{
struct dbox_index_record *rec;
enum dbox_index_file_status status;
int ret;
} else {
/* file doesn't exist, nothing to do */
return 1;
}
}
if (status == DBOX_INDEX_FILE_STATUS_SINGLE_MESSAGE &&
/* fast path to expunging the whole file */
if (dbox_sync_file_unlink(file) < 0)
ret = -1;
else {
ret = 1;
}
} else {
}
return ret;
}