dovecot-2.2: lib-storage: Make sure index root dir is created wh...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 10 14:01:00 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/52233547b371
changeset: 16260:52233547b371
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Apr 10 14:00:47 2013 +0300
description:
lib-storage: Make sure index root dir is created when mailbox list index is created.

diffstat:

 src/lib-storage/list/mailbox-list-index.c |   3 ++
 src/lib-storage/mailbox-list.c            |  46 ++++++++++++++++++++----------
 src/lib-storage/mailbox-list.h            |   4 ++
 3 files changed, 38 insertions(+), 15 deletions(-)

diffs (101 lines):

diff -r 8da591260f7c -r 52233547b371 src/lib-storage/list/mailbox-list-index.c
--- a/src/lib-storage/list/mailbox-list-index.c	Wed Apr 10 13:40:57 2013 +0300
+++ b/src/lib-storage/list/mailbox-list-index.c	Wed Apr 10 14:00:47 2013 +0300
@@ -47,6 +47,9 @@
 	if (ilist->opened)
 		return 0;
 
+	if (mailbox_list_mkdir_missing_index_root(list) < 0)
+		return -1;
+
 	index_flags = mail_storage_settings_to_index_flags(set);
 	if (strcmp(list->name, MAILBOX_LIST_NAME_INDEX) == 0) {
 		/* LAYOUT=index. this is the only location for the mailbox
diff -r 8da591260f7c -r 52233547b371 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Wed Apr 10 13:40:57 2013 +0300
+++ b/src/lib-storage/mailbox-list.c	Wed Apr 10 14:00:47 2013 +0300
@@ -1107,6 +1107,8 @@
 		mailbox_list_set_critical(list, "%s", error);
 		return -1;
 	}
+	if (type == MAILBOX_LIST_PATH_TYPE_INDEX)
+		list->index_root_dir_created = TRUE;
 	return 0;
 }
 
@@ -1439,32 +1441,46 @@
 	return TRUE;
 }
 
+int mailbox_list_mkdir_missing_index_root(struct mailbox_list *list)
+{
+	const char *root_dir, *index_dir;
+	int ret;
+
+	if (list->index_root_dir_created)
+		return 1;
+
+	/* if index root dir hasn't been created yet, do it now */
+	ret = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_INDEX,
+					 &index_dir);
+	if (ret <= 0)
+		return ret;
+	ret = mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_MAILBOX,
+					 &root_dir);
+	if (ret <= 0)
+		return ret;
+
+	if (strcmp(root_dir, index_dir) != 0) {
+		if (mailbox_list_mkdir_root(list, index_dir,
+					    MAILBOX_LIST_PATH_TYPE_INDEX) < 0)
+			return -1;
+	}
+	list->index_root_dir_created = TRUE;
+	return 1;
+}
+
 void mailbox_list_add_change(struct mailbox_list *list,
 			     enum mailbox_log_record_type type,
 			     const guid_128_t mailbox_guid)
 {
 	struct mailbox_log_record rec;
-	const char *root_dir, *index_dir;
 	time_t stamp;
 
 	if (!mailbox_list_init_changelog(list) ||
 	    guid_128_is_empty(mailbox_guid))
 		return;
 
-	if (!list->index_root_dir_created) {
-		/* if index root dir hasn't been created yet, do it now */
-		if (mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_INDEX,
-					       &index_dir) <= 0)
-			return;
-		if (mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_MAILBOX,
-					       &root_dir) <= 0 ||
-		    strcmp(root_dir, index_dir) != 0) {
-			if (mailbox_list_mkdir_root(list, index_dir,
-						    MAILBOX_LIST_PATH_TYPE_INDEX) < 0)
-				return;
-		}
-		list->index_root_dir_created = TRUE;
-	}
+	if (mailbox_list_mkdir_missing_index_root(list) <= 0)
+		return;
 
 	stamp = list->changelog_timestamp != (time_t)-1 ?
 		list->changelog_timestamp : ioloop_time;
diff -r 8da591260f7c -r 52233547b371 src/lib-storage/mailbox-list.h
--- a/src/lib-storage/mailbox-list.h	Wed Apr 10 13:40:57 2013 +0300
+++ b/src/lib-storage/mailbox-list.h	Wed Apr 10 14:00:47 2013 +0300
@@ -181,6 +181,10 @@
 int mailbox_list_try_mkdir_root(struct mailbox_list *list, const char *path,
 				enum mailbox_list_path_type type,
 				const char **error_r);
+/* Call mailbox_list_mkdir_root() for index, unless the index root is the
+   same as mailbox root. Returns 1 if ok, 0 if there are no indexes, -1 if
+   error. Calling this multiple times does the check only once. */
+int mailbox_list_mkdir_missing_index_root(struct mailbox_list *list);
 
 /* Returns TRUE if name is ok, FALSE if it can't be safely passed to
    mailbox_list_*() functions */


More information about the dovecot-cvs mailing list