From: Timo Sirainen Date: Tue, 21 Oct 2014 00:58:56 +0000 (+0300) Subject: lib-storage: Added mailbox_list_index_delete_entry() X-Git-Tag: 2.2.15~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c44f7761bba61503d573eb950b9377f9d55ce2aa;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Added mailbox_list_index_delete_entry() --- diff --git a/src/lib-storage/list/mailbox-list-index-backend.c b/src/lib-storage/list/mailbox-list-index-backend.c index 373769b410..74f4a62906 100644 --- a/src/lib-storage/list/mailbox-list-index-backend.c +++ b/src/lib-storage/list/mailbox-list-index-backend.c @@ -413,10 +413,9 @@ index_list_mailbox_exists(struct mailbox *box, bool auto_boxes ATTR_UNUSED, } static void -index_list_try_delete(struct index_mailbox_list *list, const char *name, +index_list_try_delete(struct mailbox_list *_list, const char *name, enum mailbox_list_path_type type) { - struct mailbox_list *_list = &list->list; const char *mailbox_path, *path; if (mailbox_list_get_path(_list, name, MAILBOX_LIST_PATH_TYPE_MAILBOX, @@ -446,73 +445,16 @@ index_list_try_delete(struct index_mailbox_list *list, const char *name, } static void -index_list_delete_finish(struct index_mailbox_list *list, const char *name) +index_list_delete_finish(struct mailbox_list *list, const char *name) { index_list_try_delete(list, name, MAILBOX_LIST_PATH_TYPE_INDEX); index_list_try_delete(list, name, MAILBOX_LIST_PATH_TYPE_CONTROL); index_list_try_delete(list, name, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX); } -static int -index_list_delete_entry(struct index_mailbox_list *list, const char *name, - bool delete_selectable) -{ - struct mailbox_list_index_sync_context *sync_ctx; - struct mailbox_list_index_record rec; - struct mailbox_list_index_node *node; - const void *data; - bool expunged; - uint32_t seq; - - if (mailbox_list_index_sync_begin(&list->list, &sync_ctx) < 0) - return -1; - - node = mailbox_list_index_lookup(&list->list, name); - if (node == NULL) { - (void)mailbox_list_index_sync_end(&sync_ctx, FALSE); - mailbox_list_set_error(&list->list, MAIL_ERROR_NOTFOUND, - T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); - return -1; - } - if (!mail_index_lookup_seq(sync_ctx->view, node->uid, &seq)) - i_panic("mailbox list index: lost uid=%u", node->uid); - if (delete_selectable) { - /* make it at least non-selectable */ - node->flags = MAILBOX_LIST_INDEX_FLAG_NOSELECT; - mail_index_update_flags(sync_ctx->trans, seq, MODIFY_REPLACE, - (enum mail_flags)node->flags); - - mail_index_lookup_ext(sync_ctx->view, seq, - sync_ctx->ilist->ext_id, - &data, &expunged); - i_assert(data != NULL && !expunged); - memcpy(&rec, data, sizeof(rec)); - rec.uid_validity = 0; - memset(&rec.guid, 0, sizeof(rec.guid)); - mail_index_update_ext(sync_ctx->trans, seq, - sync_ctx->ilist->ext_id, &rec, NULL); - } - if (node->children != NULL) { - /* can't delete this directory before its children, - but we may have made it non-selectable already */ - if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0) - return -1; - return 0; - } - - /* we can remove the entire node */ - mail_index_expunge(sync_ctx->trans, seq); - mailbox_list_index_node_unlink(sync_ctx->ilist, node); - - if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0) - return -1; - return 1; -} - static int index_list_delete_mailbox(struct mailbox_list *_list, const char *name) { - struct index_mailbox_list *list = (struct index_mailbox_list *)_list; const char *path; int ret; @@ -532,9 +474,9 @@ index_list_delete_mailbox(struct mailbox_list *_list, const char *name) } if (ret == 0 || (_list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) != 0) - index_list_delete_finish(list, name); + index_list_delete_finish(_list, name); if (ret == 0) { - if (index_list_delete_entry(list, name, TRUE) < 0) + if (mailbox_list_index_delete_entry(_list, name, TRUE) < 0) return -1; } return ret; @@ -543,10 +485,9 @@ index_list_delete_mailbox(struct mailbox_list *_list, const char *name) static int index_list_delete_dir(struct mailbox_list *_list, const char *name) { - struct index_mailbox_list *list = (struct index_mailbox_list *)_list; int ret; - if ((ret = index_list_delete_entry(list, name, FALSE)) < 0) + if ((ret = mailbox_list_index_delete_entry(_list, name, FALSE)) < 0) return -1; if (ret == 0) { mailbox_list_set_error(_list, MAIL_ERROR_EXISTS, diff --git a/src/lib-storage/list/mailbox-list-index-sync.c b/src/lib-storage/list/mailbox-list-index-sync.c index dbd8431960..eb480d2e9e 100644 --- a/src/lib-storage/list/mailbox-list-index-sync.c +++ b/src/lib-storage/list/mailbox-list-index-sync.c @@ -394,3 +394,58 @@ int mailbox_list_index_sync(struct mailbox_list *list) ret = mailbox_list_index_sync_list(sync_ctx); return mailbox_list_index_sync_end(&sync_ctx, ret == 0); } + +int mailbox_list_index_delete_entry(struct mailbox_list *list, const char *name, + bool delete_selectable) +{ + struct mailbox_list_index_sync_context *sync_ctx; + struct mailbox_list_index_record rec; + struct mailbox_list_index_node *node; + const void *data; + bool expunged; + uint32_t seq; + + if (mailbox_list_index_sync_begin(list, &sync_ctx) < 0) + return -1; + + node = mailbox_list_index_lookup(list, name); + if (node == NULL) { + (void)mailbox_list_index_sync_end(&sync_ctx, FALSE); + mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, + T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); + return -1; + } + if (!mail_index_lookup_seq(sync_ctx->view, node->uid, &seq)) + i_panic("mailbox list index: lost uid=%u", node->uid); + if (delete_selectable) { + /* make it at least non-selectable */ + node->flags = MAILBOX_LIST_INDEX_FLAG_NOSELECT; + mail_index_update_flags(sync_ctx->trans, seq, MODIFY_REPLACE, + (enum mail_flags)node->flags); + + mail_index_lookup_ext(sync_ctx->view, seq, + sync_ctx->ilist->ext_id, + &data, &expunged); + i_assert(data != NULL && !expunged); + memcpy(&rec, data, sizeof(rec)); + rec.uid_validity = 0; + memset(&rec.guid, 0, sizeof(rec.guid)); + mail_index_update_ext(sync_ctx->trans, seq, + sync_ctx->ilist->ext_id, &rec, NULL); + } + if (node->children != NULL) { + /* can't delete this directory before its children, + but we may have made it non-selectable already */ + if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0) + return -1; + return 0; + } + + /* we can remove the entire node */ + mail_index_expunge(sync_ctx->trans, seq); + mailbox_list_index_node_unlink(sync_ctx->ilist, node); + + if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0) + return -1; + return 1; +} diff --git a/src/lib-storage/list/mailbox-list-index-sync.h b/src/lib-storage/list/mailbox-list-index-sync.h index e8f60c7a20..3cf7a49321 100644 --- a/src/lib-storage/list/mailbox-list-index-sync.h +++ b/src/lib-storage/list/mailbox-list-index-sync.h @@ -29,4 +29,7 @@ uint32_t mailbox_list_index_sync_name(struct mailbox_list_index_sync_context *ct struct mailbox_list_index_node **node_r, bool *created_r); +int mailbox_list_index_delete_entry(struct mailbox_list *list, const char *name, + bool delete_selectable); + #endif