const void *data;
uint32_t seq;
bool expunged;
-
- (void)dbox_map_refresh(map);
+ int ret;
if (array_is_created(&map->ref0_file_ids))
array_clear(&map->ref0_file_ids);
else
i_array_init(&map->ref0_file_ids, 64);
+
+ if ((ret = dbox_map_open(map, FALSE)) <= 0) {
+ /* map doesn't exist or is broken */
+ return &map->ref0_file_ids;
+ }
+ (void)dbox_map_refresh(map);
+
hdr = mail_index_get_header(map->view);
for (seq = 1; seq <= hdr->messages_count; seq++) {
mail_index_lookup_ext(map->view, seq, map->ref_ext_id,
&data, &expunged);
if (data != NULL && !expunged) {
rec = data;
- seq_range_array_add(&map->ref0_file_ids, 0, seq);
+ seq_range_array_add(&map->ref0_file_ids, 0,
+ rec->file_id);
}
}
return &map->ref0_file_ids;
}
struct dbox_map_append_context *
-dbox_map_append_begin(struct dbox_mailbox *mbox)
+dbox_map_append_begin_storage(struct dbox_storage *storage)
{
struct dbox_map_append_context *ctx;
int ret;
ctx = i_new(struct dbox_map_append_context, 1);
- ctx->map = mbox->storage->map;
- ctx->mbox = mbox;
+ ctx->map = storage->map;
ctx->first_new_file_id = (uint32_t)-1;
i_array_init(&ctx->files, 64);
i_array_init(&ctx->appends, 128);
return ctx;
}
+struct dbox_map_append_context *
+dbox_map_append_begin(struct dbox_mailbox *mbox)
+{
+ struct dbox_map_append_context *ctx;
+
+ ctx = dbox_map_append_begin_storage(mbox->storage);
+ ctx->mbox = mbox;
+ return ctx;
+}
+
static time_t day_begin_stamp(unsigned int days)
{
struct tm tm;
time_t stamp;
+
if (days == 0)
return 0;
#define DBOX_MAP_H
struct dbox_storage;
+struct dbox_mailbox;
struct dbox_file;
struct dbox_map_append_context;
struct dbox_map_append_context *
dbox_map_append_begin(struct dbox_mailbox *mbox);
+struct dbox_map_append_context *
+dbox_map_append_begin_storage(struct dbox_storage *storage);
/* Request file for saving a new message with given size (if available). If an
existing file can be used, the record is locked and updated in index.
Returns 0 if ok, -1 if error. */
#include "index-mail.h"
#include "mail-copy.h"
#include "maildir/maildir-uidlist.h"
-#include "dbox-sync.h"
#include "dbox-map.h"
#include "dbox-file.h"
+#include "dbox-sync.h"
#include "dbox-storage.h"
#include <stdio.h>
{
struct dbox_storage *storage = (struct dbox_storage *)_storage;
+ dbox_sync_cleanup(storage);
dbox_files_free(storage);
dbox_map_deinit(&storage->map);
array_free(&storage->open_files);
return 1;
}
-static int
-dbox_sync_file_cleanup(struct dbox_sync_context *ctx, struct dbox_file *file)
+int dbox_sync_file_cleanup(struct dbox_file *file)
{
struct dbox_file *out_file;
struct istream *input;
if ((ret = dbox_file_try_lock(file)) <= 0)
return ret;
- append_ctx = dbox_map_append_begin(ctx->mbox);
+ append_ctx = dbox_map_append_begin_storage(file->storage);
t_array_init(&msgs_arr, 128);
- if (dbox_map_get_file_msgs(ctx->mbox->storage->map, file->file_id,
+ if (dbox_map_get_file_msgs(file->storage->map, file->file_id,
&msgs_arr) < 0) {
// FIXME
return -1;
const struct dbox_sync_file_entry *entry)
{
struct dbox_file *file;
- bool deleted;
int ret;
file = entry->file_id != 0 ?
return -1;
dbox_sync_mark_expunges(ctx, &entry->expunge_seqs);
-
- /* FIXME: do this cleanup later */
- ret = dbox_file_open_or_create(file, &deleted);
- if (ret > 0 && !deleted)
- ret = dbox_sync_file_cleanup(ctx, file);
}
dbox_file_unref(&file);
return ret;
void dbox_sync_cleanup(struct dbox_storage *storage)
{
const ARRAY_TYPE(seq_range) *ref0_file_ids;
+ struct dbox_file *file;
+ struct seq_range_iter iter;
unsigned int i = 0;
+ uint32_t file_id;
+ bool deleted;
ref0_file_ids = dbox_map_get_zero_ref_files(storage->map);
+ seq_range_array_iter_init(&iter, ref0_file_ids); i = 0;
+ while (seq_range_array_iter_nth(&iter, i++, &file_id)) {
+ file = dbox_file_init_multi(storage, file_id);
+ if (dbox_file_open_or_create(file, &deleted) > 0 && !deleted)
+ (void)dbox_sync_file_cleanup(file);
+ dbox_file_unref(&file);
+ }
}
#define DBOX_SYNC_H
struct mailbox;
+struct dbox_mailbox;
struct dbox_sync_file_entry {
uint32_t uid, file_id;
int dbox_sync_finish(struct dbox_sync_context **ctx, bool success);
int dbox_sync(struct dbox_mailbox *mbox);
+void dbox_sync_cleanup(struct dbox_storage *storage);
int dbox_sync_file(struct dbox_sync_context *ctx,
const struct dbox_sync_file_entry *entry);
+int dbox_sync_file_cleanup(struct dbox_file *file);
int dbox_sync_index_rebuild(struct dbox_mailbox *mbox);
struct mailbox_sync_context *