Mercurial > dovecot > core-2.2
changeset 10525:c3d85a07888c HEAD
mdbox: Fixed rebuilding mdbox storage.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 22 Dec 2009 18:12:33 -0500 |
parents | 824b7072c6d9 |
children | e1b725d02c30 |
files | src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c |
diffstat | 1 files changed, 48 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Tue Dec 22 18:12:19 2009 -0500 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Tue Dec 22 18:12:33 2009 -0500 @@ -128,41 +128,17 @@ return 0; } -static int rebuild_add_file(struct mdbox_storage_rebuild_context *ctx, - const char *path) +static int rebuild_file_mails(struct mdbox_storage_rebuild_context *ctx, + struct dbox_file *file) { - struct dbox_file *file; - const char *fname, *guid; + const char *guid; struct mdbox_rebuild_msg *rec; - uint32_t file_id; uoff_t offset, prev_offset, size; bool last, first, fixed = FALSE; - unsigned int len; - int ret = 0; - - fname = strrchr(path, '/'); - i_assert(fname != NULL); - fname += strlen(MDBOX_MAIL_FILE_PREFIX) + 1; + int ret; - file_id = strtoul(fname, NULL, 10); - if (!is_numeric(fname, '\0') || file_id == 0) { - len = strlen(fname); - if (len > 7 && strcmp(fname + len - 7, ".broken") != 0) { - i_warning("dbox rebuild: File name is missing ID: %s", - path); - } - return 0; - } - - /* small optimization: typically files are returned sorted. in that - case we don't need to sort them ourself. */ - if (file_id < ctx->prev_file_id) - ctx->msgs_unsorted = TRUE; - ctx->prev_file_id = file_id; - - file = mdbox_file_init(ctx->storage, file_id); + dbox_file_seek_rewind(file); prev_offset = 0; - dbox_file_seek_rewind(file); while ((ret = dbox_file_seek_next(file, &offset, &last)) >= 0) { if (ret > 0) { if ((ret = dbox_file_metadata_read(file)) < 0) @@ -203,7 +179,7 @@ } rec = p_new(ctx->pool, struct mdbox_rebuild_msg, 1); - rec->file_id = file_id; + rec->file_id = ctx->prev_file_id; rec->offset = offset; rec->size = file->input->v_offset - offset; mail_generate_guid_128_hash(guid, rec->guid_128); @@ -217,7 +193,48 @@ hash_table_insert(ctx->guid_hash, rec->guid_128, rec); } } - if (ret == 0 && !last) + if (ret < 0) + return -1; + else if (ret == 0 && !last) + return 0; + else + return 1; +} + +static int rebuild_add_file(struct mdbox_storage_rebuild_context *ctx, + const char *path) +{ + struct dbox_file *file; + uint32_t file_id; + const char *fname; + unsigned int len; + bool deleted; + int ret = 0; + + fname = strrchr(path, '/'); + i_assert(fname != NULL); + fname += strlen(MDBOX_MAIL_FILE_PREFIX) + 1; + + file_id = strtoul(fname, NULL, 10); + if (!is_numeric(fname, '\0') || file_id == 0) { + len = strlen(fname); + if (len > 7 && strcmp(fname + len - 7, ".broken") != 0) { + i_warning("dbox rebuild: File name is missing ID: %s", + path); + } + return 0; + } + + /* small optimization: typically files are returned sorted. in that + case we don't need to sort them ourself. */ + if (file_id < ctx->prev_file_id) + ctx->msgs_unsorted = TRUE; + ctx->prev_file_id = file_id; + + file = mdbox_file_init(ctx->storage, file_id); + if ((ret = dbox_file_open(file, &deleted)) > 0 && !deleted) + ret = rebuild_file_mails(ctx, file); + if (ret == 0) i_error("dbox rebuild: Failed to fix file %s", path); dbox_file_unref(&file); return ret < 0 ? -1 : 0;