Mercurial > dovecot > core-2.2
changeset 12740:159605040ec0
dbox index rebuild: If alt dir isn't mounted (can't be mkdir()ed), abort rebuild.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 17 Feb 2011 09:54:26 +0200 |
parents | c9af551124fb |
children | 7ce47a476656 |
files | src/lib-storage/index/dbox-common/dbox-sync-rebuild.c src/lib-storage/index/dbox-common/dbox-sync-rebuild.h src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c |
diffstat | 4 files changed, 46 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c Thu Feb 17 09:32:35 2011 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.c Thu Feb 17 09:54:26 2011 +0200 @@ -3,6 +3,7 @@ #include "lib.h" #include "array.h" #include "mail-index-modseq.h" +#include "mailbox-list-private.h" #include "index-storage.h" #include "dbox-storage.h" #include "dbox-sync-rebuild.h" @@ -190,3 +191,29 @@ } i_free(ctx); } + +int dbox_sync_rebuild_verify_alt_storage(struct mailbox_list *list) +{ + const char *alt_path; + struct stat st; + + alt_path = mailbox_list_get_path(list, NULL, + MAILBOX_LIST_PATH_TYPE_ALT_DIR); + if (alt_path == NULL) + return 0; + + /* make sure alt storage is mounted. if it's not, abort the rebuild. */ + if (stat(alt_path, &st) == 0) + return 0; + if (errno != ENOENT) { + i_error("stat(%s) failed: %m", alt_path); + return -1; + } + + /* try to create the alt directory. if it fails, it means alt + storage isn't mounted. */ + if (mailbox_list_mkdir(list, alt_path, + MAILBOX_LIST_PATH_TYPE_ALT_DIR) < 0) + return -1; + return 0; +}
--- a/src/lib-storage/index/dbox-common/dbox-sync-rebuild.h Thu Feb 17 09:32:35 2011 +0200 +++ b/src/lib-storage/index/dbox-common/dbox-sync-rebuild.h Thu Feb 17 09:54:26 2011 +0200 @@ -1,6 +1,8 @@ #ifndef DBOX_SYNC_REBUILD_H #define DBOX_SYNC_REBUILD_H +struct mailbox_list; + struct dbox_sync_rebuild_context { struct mailbox *box; @@ -23,5 +25,6 @@ void dbox_sync_rebuild_index_metadata(struct dbox_sync_rebuild_context *ctx, uint32_t new_seq, uint32_t uid); +int dbox_sync_rebuild_verify_alt_storage(struct mailbox_list *list); #endif
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Thu Feb 17 09:32:35 2011 +0200 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Thu Feb 17 09:54:26 2011 +0200 @@ -9,6 +9,7 @@ #include "mail-cache.h" #include "dbox-sync-rebuild.h" #include "mail-namespace.h" +#include "mailbox-list-private.h" #include "mdbox-storage.h" #include "mdbox-file.h" #include "mdbox-map-private.h" @@ -892,6 +893,14 @@ struct mdbox_storage_rebuild_context *ctx; int ret; + if (dbox_sync_rebuild_verify_alt_storage(storage->map->root_list) < 0) { + mail_storage_set_critical(&storage->storage.storage, + "mdbox rebuild: Alt storage %s not mounted, aborting", + storage->alt_storage_dir); + mdbox_map_atomic_set_failed(atomic); + return -1; + } + ctx = mdbox_storage_rebuild_init(storage, atomic); ret = mdbox_storage_rebuild_scan(ctx); mdbox_storage_rebuild_deinit(ctx);
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c Thu Feb 17 09:32:35 2011 +0200 +++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c Thu Feb 17 09:54:26 2011 +0200 @@ -177,6 +177,13 @@ } } + if (dbox_sync_rebuild_verify_alt_storage(mbox->box.list) < 0) { + mail_storage_set_critical(mbox->box.storage, + "sdbox %s: Alt storage not mounted, " + "aborting index rebuild", mbox->box.path); + return -1; + } + mail_cache_reset(mbox->box.cache); view = mail_index_view_open(mbox->box.index);