From 16d45b0a938b583906a2e3b9be80ccb46f2825c0 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 16 Mar 2010 15:20:15 +0200 Subject: [PATCH] mdbox: Rebuilding storage ignored mails in alt storage. --HG-- branch : HEAD --- .../index/dbox-multi/mdbox-storage-rebuild.c | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index 34837a5798..a274f16376 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -735,46 +735,27 @@ static int rebuild_finish(struct mdbox_storage_rebuild_context *ctx) return 0; } -static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx) +static int +mdbox_storage_rebuild_scan_dir(struct mdbox_storage_rebuild_context *ctx, + const char *storage_dir, bool alt) { - const struct mail_index_header *hdr; DIR *dir; struct dirent *d; string_t *path; unsigned int dir_len; - uint32_t uid_validity; int ret = 0; - if (dbox_map_open(ctx->storage->map, TRUE) < 0) - return -1; - - /* begin by locking the map, so that other processes can't try to - rebuild at the same time. */ - ret = mail_index_sync_begin(ctx->storage->map->index, &ctx->sync_ctx, - &ctx->sync_view, &ctx->trans, 0); - if (ret <= 0) { - i_assert(ret != 0); - mail_storage_set_internal_error(&ctx->storage->storage.storage); - mail_index_reset_error(ctx->storage->map->index); - return -1; - } - - uid_validity = dbox_map_get_uid_validity(ctx->storage->map); - hdr = mail_index_get_header(ctx->sync_view); - if (hdr->uid_validity != uid_validity) { - mail_index_update_header(ctx->trans, - offsetof(struct mail_index_header, uid_validity), - &uid_validity, sizeof(uid_validity), TRUE); - } - - dir = opendir(ctx->storage->storage_dir); + dir = opendir(storage_dir); if (dir == NULL) { + if (alt && errno == ENOENT) + return 0; + mail_storage_set_critical(&ctx->storage->storage.storage, - "opendir(%s) failed: %m", ctx->storage->storage_dir); + "opendir(%s) failed: %m", storage_dir); return -1; } path = t_str_new(256); - str_append(path, ctx->storage->storage_dir); + str_append(path, storage_dir); str_append_c(path, '/'); dir_len = str_len(path); @@ -794,14 +775,51 @@ static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx) } if (ret == 0 && errno != 0) { mail_storage_set_critical(&ctx->storage->storage.storage, - "readdir(%s) failed: %m", ctx->storage->storage_dir); + "readdir(%s) failed: %m", storage_dir); ret = -1; } if (closedir(dir) < 0) { mail_storage_set_critical(&ctx->storage->storage.storage, - "closedir(%s) failed: %m", ctx->storage->storage_dir); + "closedir(%s) failed: %m", storage_dir); ret = -1; } + return ret; +} + +static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx) +{ + const struct mail_index_header *hdr; + uint32_t uid_validity; + int ret = 0; + + if (dbox_map_open(ctx->storage->map, TRUE) < 0) + return -1; + + /* begin by locking the map, so that other processes can't try to + rebuild at the same time. */ + ret = mail_index_sync_begin(ctx->storage->map->index, &ctx->sync_ctx, + &ctx->sync_view, &ctx->trans, 0); + if (ret <= 0) { + i_assert(ret != 0); + mail_storage_set_internal_error(&ctx->storage->storage.storage); + mail_index_reset_error(ctx->storage->map->index); + return -1; + } + + uid_validity = dbox_map_get_uid_validity(ctx->storage->map); + hdr = mail_index_get_header(ctx->sync_view); + if (hdr->uid_validity != uid_validity) { + mail_index_update_header(ctx->trans, + offsetof(struct mail_index_header, uid_validity), + &uid_validity, sizeof(uid_validity), TRUE); + } + + if (mdbox_storage_rebuild_scan_dir(ctx, ctx->storage->storage_dir, + FALSE) < 0) + return -1; + if (mdbox_storage_rebuild_scan_dir(ctx, ctx->storage->alt_storage_dir, + TRUE) < 0) + return -1; if (ret < 0 || rebuild_apply_map(ctx) < 0 || -- 2.47.3