dovecot-2.0: dbox index rebuild: If alt dir isn't mounted (can't...

dovecot at dovecot.org dovecot at dovecot.org
Thu Feb 17 09:54:29 EET 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/159605040ec0
changeset: 12605:159605040ec0
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Feb 17 09:54:26 2011 +0200
description:
dbox index rebuild: If alt dir isn't mounted (can't be mkdir()ed), abort rebuild.

diffstat:

 src/lib-storage/index/dbox-common/dbox-sync-rebuild.c    |  27 +++++++++++++
 src/lib-storage/index/dbox-common/dbox-sync-rebuild.h    |   3 +
 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c |   9 ++++
 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c   |   7 +++
 4 files changed, 46 insertions(+), 0 deletions(-)

diffs (103 lines):

diff -r c9af551124fb -r 159605040ec0 src/lib-storage/index/dbox-common/dbox-sync-rebuild.c
--- 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;
+}
diff -r c9af551124fb -r 159605040ec0 src/lib-storage/index/dbox-common/dbox-sync-rebuild.h
--- 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
diff -r c9af551124fb -r 159605040ec0 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
--- 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);
diff -r c9af551124fb -r 159605040ec0 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
--- 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);


More information about the dovecot-cvs mailing list