From e6d3565f21364d97cfc0b9ba65bb80fbe2d76a7f Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 5 Mar 2009 16:28:56 -0500 Subject: [PATCH] dbox: File cleanup is for now done in logout. --HG-- branch : HEAD --- src/lib-storage/index/dbox/dbox-map.c | 29 ++++++++++++++++----- src/lib-storage/index/dbox/dbox-map.h | 3 +++ src/lib-storage/index/dbox/dbox-storage.c | 3 ++- src/lib-storage/index/dbox/dbox-sync-file.c | 13 +++------ src/lib-storage/index/dbox/dbox-sync.c | 11 ++++++++ src/lib-storage/index/dbox/dbox-sync.h | 3 +++ 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/lib-storage/index/dbox/dbox-map.c b/src/lib-storage/index/dbox/dbox-map.c index 2c3ebf3461..faa80d84ce 100644 --- a/src/lib-storage/index/dbox/dbox-map.c +++ b/src/lib-storage/index/dbox/dbox-map.c @@ -242,13 +242,19 @@ const ARRAY_TYPE(seq_range) *dbox_map_get_zero_ref_files(struct dbox_map *map) 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, @@ -263,7 +269,8 @@ const ARRAY_TYPE(seq_range) *dbox_map_get_zero_ref_files(struct dbox_map *map) &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; @@ -302,14 +309,13 @@ int dbox_map_update_refcounts(struct dbox_map *map, } 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); @@ -323,11 +329,22 @@ dbox_map_append_begin(struct dbox_mailbox *mbox) 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; diff --git a/src/lib-storage/index/dbox/dbox-map.h b/src/lib-storage/index/dbox/dbox-map.h index 18a8d4c8b6..3213d7e542 100644 --- a/src/lib-storage/index/dbox/dbox-map.h +++ b/src/lib-storage/index/dbox/dbox-map.h @@ -2,6 +2,7 @@ #define DBOX_MAP_H struct dbox_storage; +struct dbox_mailbox; struct dbox_file; struct dbox_map_append_context; @@ -30,6 +31,8 @@ const ARRAY_TYPE(seq_range) *dbox_map_get_zero_ref_files(struct dbox_map *map); 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. */ diff --git a/src/lib-storage/index/dbox/dbox-storage.c b/src/lib-storage/index/dbox/dbox-storage.c index 193e6f40b1..c19066845e 100644 --- a/src/lib-storage/index/dbox/dbox-storage.c +++ b/src/lib-storage/index/dbox/dbox-storage.c @@ -9,9 +9,9 @@ #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 @@ -202,6 +202,7 @@ static void dbox_destroy(struct mail_storage *_storage) { 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); diff --git a/src/lib-storage/index/dbox/dbox-sync-file.c b/src/lib-storage/index/dbox/dbox-sync-file.c index b4ec2d2227..db44241364 100644 --- a/src/lib-storage/index/dbox/dbox-sync-file.c +++ b/src/lib-storage/index/dbox/dbox-sync-file.c @@ -42,8 +42,7 @@ static int dbox_sync_file_unlink(struct dbox_file *file) 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; @@ -64,10 +63,10 @@ dbox_sync_file_cleanup(struct dbox_sync_context *ctx, struct dbox_file *file) 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; @@ -208,7 +207,6 @@ int dbox_sync_file(struct dbox_sync_context *ctx, const struct dbox_sync_file_entry *entry) { struct dbox_file *file; - bool deleted; int ret; file = entry->file_id != 0 ? @@ -230,11 +228,6 @@ int dbox_sync_file(struct dbox_sync_context *ctx, 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; diff --git a/src/lib-storage/index/dbox/dbox-sync.c b/src/lib-storage/index/dbox/dbox-sync.c index 0b37817e13..053a1c677c 100644 --- a/src/lib-storage/index/dbox/dbox-sync.c +++ b/src/lib-storage/index/dbox/dbox-sync.c @@ -318,7 +318,18 @@ dbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) 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); + } } diff --git a/src/lib-storage/index/dbox/dbox-sync.h b/src/lib-storage/index/dbox/dbox-sync.h index a0136ea4b6..b8e40a14b3 100644 --- a/src/lib-storage/index/dbox/dbox-sync.h +++ b/src/lib-storage/index/dbox/dbox-sync.h @@ -2,6 +2,7 @@ #define DBOX_SYNC_H struct mailbox; +struct dbox_mailbox; struct dbox_sync_file_entry { uint32_t uid, file_id; @@ -30,8 +31,10 @@ int dbox_sync_begin(struct dbox_mailbox *mbox, bool force, 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 * -- 2.47.3