[dovecot-cvs] dovecot/src/lib-storage/list index-mailbox-list.c, 1.4, 1.5

tss at dovecot.org tss at dovecot.org
Thu Jan 18 16:56:59 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/list
In directory talvi:/tmp/cvs-serv22175

Modified Files:
	index-mailbox-list.c 
Log Message:
Cleanups



Index: index-mailbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/list/index-mailbox-list.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- index-mailbox-list.c	20 Dec 2006 08:16:42 -0000	1.4
+++ index-mailbox-list.c	18 Jan 2007 16:56:57 -0000	1.5
@@ -336,20 +336,15 @@
 	ilist->super.deinit(list);
 }
 
-static void index_mailbox_list_created(struct mailbox_list *list)
+static int index_mailbox_list_open_indexes(struct mailbox_list *list,
+					   const char *dir)
 {
-	struct index_mailbox_list *ilist;
-	struct mail_index *mail_index;
-	struct mailbox_list_index *list_index;
+	struct index_mailbox_list *ilist = INDEX_LIST_CONTEXT(list);
+	const char *path;
 	enum mail_index_open_flags index_flags;
 	enum mail_storage_flags storage_flags;
-	const char *dir, *path;
 	int ret;
 
-	/* FIXME: for now we only work with maildir++ */
-	if (strcmp(list->name, "maildir++") != 0)
-		return;
-
 	/* FIXME: a bit ugly way to get the flags, but this will do for now.. */
 	index_flags = MAIL_INDEX_OPEN_FLAG_CREATE;
 	storage_flags = *list->set.mail_storage_flags;
@@ -360,40 +355,44 @@
 #endif
 		index_flags |= MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE;
 
-	dir = mailbox_list_get_path(list, NULL, MAILBOX_LIST_PATH_TYPE_INDEX);
-	path = t_strconcat(dir, "/"MAILBOX_LIST_INDEX_NAME, NULL);
-
-	mail_index = mail_index_alloc(dir, MAIL_INDEX_PREFIX);
-	if (mail_index_open(mail_index, index_flags,
+	if (mail_index_open(ilist->mail_index, index_flags,
 			    *list->set.lock_method) < 0) {
-		if (mail_index_move_to_memory(mail_index) < 0) {
+		if (mail_index_move_to_memory(ilist->mail_index) < 0) {
 			/* try opening once more. it should be created
 			   directly into memory now. */
-			ret = mail_index_open(mail_index, index_flags,
+			ret = mail_index_open(ilist->mail_index, index_flags,
 					      *list->set.lock_method);
 			if (ret <= 0) {
 				/* everything failed. there's a bug in the
 				   code, but just work around it by disabling
 				   the index completely */
-				mail_index_free(&mail_index);
-				return;
+				return -1;
 			}
 		}
 	}
 
-	list_index = mailbox_list_index_alloc(path, list->hierarchy_sep,
-					      mail_index);
-	if (mailbox_list_index_open_or_create(list_index) < 0) {
+	path = t_strconcat(dir, "/"MAILBOX_LIST_INDEX_NAME, NULL);
+	ilist->list_index = mailbox_list_index_alloc(path, list->hierarchy_sep,
+						     ilist->mail_index);
+	if (mailbox_list_index_open_or_create(ilist->list_index) < 0) {
 		/* skip indexing */
-		mailbox_list_index_free(&list_index);
-		mail_index_free(&mail_index);
-		return;
+		mailbox_list_index_free(&ilist->list_index);
+		return -1;
 	}
+	return 0;
+}
+
+static void index_mailbox_list_created(struct mailbox_list *list)
+{
+	struct index_mailbox_list *ilist;
+	const char *dir;
+
+	/* FIXME: for now we only work with maildir++ */
+	if (strcmp(list->name, "maildir++") != 0)
+		return;
 
 	ilist = p_new(list->pool, struct index_mailbox_list, 1);
 	ilist->super = list->v;
-	ilist->mail_index = mail_index;
-	ilist->list_index = list_index;
 
 	list->v.deinit = index_mailbox_list_deinit;
 	list->v.iter_init = index_mailbox_list_iter_init;
@@ -408,7 +407,19 @@
 	array_idx_set(&list->module_contexts,
 		      index_mailbox_list_module_id, &ilist);
 
+	dir = mailbox_list_get_path(list, NULL, MAILBOX_LIST_PATH_TYPE_INDEX);
+	ilist->mail_index = mail_index_alloc(dir, MAIL_INDEX_PREFIX);
+
+	/* sync_init allocates the extensions. do it here before opening the
+	   index files, so that our initial memory pool size guesses are a
+	   bit more optimal */
 	index_mailbox_list_sync_init_list(list);
+
+	if (index_mailbox_list_open_indexes(list, dir) < 0) {
+		mail_index_free(&ilist->mail_index);
+		array_idx_clear(&list->module_contexts,
+				index_mailbox_list_module_id);
+	}
 }
 
 void index_mailbox_list_init(void); /* called in mailbox-list-register.c */



More information about the dovecot-cvs mailing list