]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
sdbox: Fixed creating mailbox with given GUID.
authorTimo Sirainen <tss@iki.fi>
Fri, 4 Mar 2011 16:19:56 +0000 (18:19 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 4 Mar 2011 16:19:56 +0000 (18:19 +0200)
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.h
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index 1d817b4a6118553fe68f3edf969c54f45a1c7018..81a79448cf5cbfcd3c94eca3f254eb1293721b2e 100644 (file)
@@ -79,7 +79,7 @@ int sdbox_read_header(struct sdbox_mailbox *mbox,
        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 @@ void sdbox_update_header(struct sdbox_mailbox *mbox,
        }
 }
 
-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 @@ static int sdbox_write_index_header(struct mailbox *box,
        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 @@ static int sdbox_mailbox_open(struct mailbox *box)
        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 @@ static int sdbox_mailbox_open(struct mailbox *box)
 
        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 @@ dbox_mailbox_update(struct mailbox *box, const struct mailbox_update *update)
        }
        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 = {
index be3961d76aa125a0d2707f9611770c9857115993..e7ebba3804df10446955cd089938b48109d826d9 100644 (file)
@@ -29,7 +29,6 @@ struct sdbox_mailbox {
        uint32_t corrupted_rebuild_count;
 
        uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
-       unsigned int creating:1;
 };
 
 extern struct mail_vfuncs sdbox_mail_vfuncs;
index a72024e51226f13a00fd5ee56b9d0d297c57d0d3..b5b46f25f8b3814c5fc9deb7ab3907dab7c10dca 100644 (file)
@@ -276,6 +276,8 @@ struct mailbox {
        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. */
index f8d67b2493e9566bf0c79dd9d8cd534a86d879e2..c22b230e9989ac720b601b3007541edc93c2aabf 100644 (file)
@@ -672,6 +672,7 @@ int mailbox_create(struct mailbox *box, const struct mailbox_update *update,
                   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 @@ int mailbox_create(struct mailbox *box, const struct mailbox_update *update,
        }
        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)