Mercurial > dovecot > core-2.2
changeset 12809:1ffeb083c993
sdbox: Fixed creating mailbox with given GUID.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 04 Mar 2011 18:19:56 +0200 |
parents | 325e163a6f84 |
children | 3f21260a72ce |
files | 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 |
diffstat | 4 files changed, 18 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- 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 = {
--- 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;
--- 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. */
--- 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)