dovecot-2.0: sdbox: Fixed creating mailbox with given GUID.

dovecot at dovecot.org dovecot at dovecot.org
Fri Mar 4 18:20:01 EET 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/1ffeb083c993
changeset: 12640:1ffeb083c993
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 04 18:19:56 2011 +0200
description:
sdbox: Fixed creating mailbox with given GUID.

diffstat:

 src/lib-storage/index/dbox-single/sdbox-storage.c |  30 +++++---------
 src/lib-storage/index/dbox-single/sdbox-storage.h |   1 -
 src/lib-storage/mail-storage-private.h            |   2 +
 src/lib-storage/mail-storage.c                    |   6 ++-
 4 files changed, 18 insertions(+), 21 deletions(-)

diffs (121 lines):

diff -r 325e163a6f84 -r 1ffeb083c993 src/lib-storage/index/dbox-single/sdbox-storage.c
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Fri Mar 04 18:09:01 2011 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Fri Mar 04 18:19:56 2011 +0200
@@ -79,7 +79,7 @@
 	mail_index_get_header_ext(view, mbox->hdr_ext_id,
 				  &data, &data_size);
 	if (data_size < SDBOX_INDEX_HEADER_MIN_SIZE &&
-	    (!mbox->creating || data_size != 0)) {
+	    (!mbox->box.creating || data_size != 0)) {
 		if (log_error) {
 			mail_storage_set_critical(
 				&mbox->storage->storage.storage,
@@ -120,9 +120,9 @@
 	}
 }
 
-static int sdbox_write_index_header(struct mailbox *box,
-				    const struct mailbox_update *update,
-				    struct mail_index_transaction *trans)
+static int sdbox_mailbox_create_indexes(struct mailbox *box,
+					const struct mailbox_update *update,
+					struct mail_index_transaction *trans)
 {
 	struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
 	struct mail_index_transaction *new_trans = NULL;
@@ -178,19 +178,6 @@
 	return 0;
 }
 
-static int sdbox_mailbox_create_indexes(struct mailbox *box,
-					const struct mailbox_update *update,
-					struct mail_index_transaction *trans)
-{
-	struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
-	int ret;
-
-	mbox->creating = TRUE;
-	ret = sdbox_write_index_header(box, update, trans);
-	mbox->creating = FALSE;
-	return ret;
-}
-
 static const char *
 sdbox_get_attachment_path_suffix(struct dbox_file *_file)
 {
@@ -227,6 +214,11 @@
 	if (dbox_mailbox_open(box) < 0)
 		return -1;
 
+	if (box->creating) {
+		/* wait for mailbox creation to initialize the index */
+		return 0;
+	}
+
 	/* get/generate mailbox guid */
 	if (sdbox_read_header(mbox, &hdr, FALSE) < 0) {
 		/* it's possible that this mailbox is just now being created
@@ -246,7 +238,7 @@
 
 	if (mail_guid_128_is_empty(hdr.mailbox_guid)) {
 		/* regenerate it */
-		if (sdbox_write_index_header(box, NULL, NULL) < 0 ||
+		if (sdbox_mailbox_create_indexes(box, NULL, NULL) < 0 ||
 		    sdbox_read_header(mbox, &hdr, TRUE) < 0)
 			return -1;
 	}
@@ -324,7 +316,7 @@
 	}
 	if (update->cache_fields != NULL)
 		index_storage_mailbox_update_cache_fields(box, update);
-	return sdbox_write_index_header(box, update, NULL);
+	return sdbox_mailbox_create_indexes(box, update, NULL);
 }
 
 struct mail_storage sdbox_storage = {
diff -r 325e163a6f84 -r 1ffeb083c993 src/lib-storage/index/dbox-single/sdbox-storage.h
--- a/src/lib-storage/index/dbox-single/sdbox-storage.h	Fri Mar 04 18:09:01 2011 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.h	Fri Mar 04 18:19:56 2011 +0200
@@ -29,7 +29,6 @@
 	uint32_t corrupted_rebuild_count;
 
 	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
-	unsigned int creating:1;
 };
 
 extern struct mail_vfuncs sdbox_mail_vfuncs;
diff -r 325e163a6f84 -r 1ffeb083c993 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Fri Mar 04 18:09:01 2011 +0200
+++ b/src/lib-storage/mail-storage-private.h	Fri Mar 04 18:19:56 2011 +0200
@@ -276,6 +276,8 @@
 	unsigned int mailbox_deleted:1;
 	/* we've discovered there aren't enough permissions to modify mailbox */
 	unsigned int backend_readonly:1;
+	/* Mailbox is being created */
+	unsigned int creating:1;
 	/* Mailbox is being deleted */
 	unsigned int deleting:1;
 	/* Mailbox was already marked as deleted within this allocation. */
diff -r 325e163a6f84 -r 1ffeb083c993 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Fri Mar 04 18:09:01 2011 +0200
+++ b/src/lib-storage/mail-storage.c	Fri Mar 04 18:19:56 2011 +0200
@@ -672,6 +672,7 @@
 		   bool directory)
 {
 	enum mailbox_dir_create_type type;
+	int ret;
 
 	if (!mailbox_list_is_valid_create_name(box->list, box->name)) {
 		mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS,
@@ -687,7 +688,10 @@
 	}
 	mailbox_refresh_permissions(box);
 
-	return box->v.create(box, update, directory);
+	box->creating = TRUE;
+	ret = box->v.create(box, update, directory);
+	box->creating = FALSE;
+	return ret;
 }
 
 int mailbox_update(struct mailbox *box, const struct mailbox_update *update)


More information about the dovecot-cvs mailing list