]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: File cleanup is for now done in logout.
authorTimo Sirainen <tss@iki.fi>
Thu, 5 Mar 2009 21:28:56 +0000 (16:28 -0500)
committerTimo Sirainen <tss@iki.fi>
Thu, 5 Mar 2009 21:28:56 +0000 (16:28 -0500)
--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-map.c
src/lib-storage/index/dbox/dbox-map.h
src/lib-storage/index/dbox/dbox-storage.c
src/lib-storage/index/dbox/dbox-sync-file.c
src/lib-storage/index/dbox/dbox-sync.c
src/lib-storage/index/dbox/dbox-sync.h

index 2c3ebf34617da5b0ae49c18181bbe870f2b554a7..faa80d84cee21bda284fdae510f22e0c400d61c6 100644 (file)
@@ -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;
 
index 18a8d4c8b6faa146700c998fd15afa789706a3db..3213d7e5421cc5ca6cfe5d230e2bf6f3ba78eb5f 100644 (file)
@@ -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. */
index 193e6f40b1b59bb91e607ace71d78e149357a64c..c19066845ea867708d8b8bc41c7c8b40e36e65bb 100644 (file)
@@ -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 <stdio.h>
@@ -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);
index b4ec2d2227e557e953a4f8d84e344d7c804fbf80..db44241364ea07ddf8f3758a28d9959e7110132a 100644 (file)
@@ -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;
index 0b37817e133a8a807b993c1a4646f452ef7f4218..053a1c677c6690c7099e8c54843a839d8c554cb6 100644 (file)
@@ -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);
+       }
 }
index a0136ea4b662e6ff0b8901789fa53154a5504317..b8e40a14b344ad8c86920d7cd6ab0e112c530f3a 100644 (file)
@@ -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 *