From b83deefd2cf1e293373673eefb4d5cf60907978c Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 7 Jun 2010 14:05:42 +0100 Subject: [PATCH] Mailbox deletion: Delay marking its index deleted until ACL has had a chance to abort the deletion. --HG-- branch : HEAD --- src/lib-storage/index/index-storage.c | 3 +++ src/lib-storage/mail-storage-private.h | 1 + src/lib-storage/mail-storage.c | 6 +----- src/plugins/lazy-expunge/lazy-expunge-plugin.c | 11 +++++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index 119dabb8fb..aaa0d1409c 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -462,6 +462,9 @@ int index_storage_mailbox_delete(struct mailbox *box) return index_storage_mailbox_delete_dir(box, FALSE); } + if (mailbox_mark_index_deleted(box, TRUE) < 0) + return -1; + if (mailbox_get_guid(box, mailbox_guid) < 0) return -1; diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 27fbdafa65..c951b5bbd6 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -463,6 +463,7 @@ void mail_storage_copy_list_error(struct mail_storage *storage, int mail_set_aborted(struct mail *mail); void mail_set_expunged(struct mail *mail); void mailbox_set_deleted(struct mailbox *box); +int mailbox_mark_index_deleted(struct mailbox *box, bool del); void mailbox_refresh_permissions(struct mailbox *box); /* Returns -1 if error, 0 if failed with EEXIST, 1 if ok */ diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 2ac68de2da..fc42858112 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -664,7 +664,7 @@ int mailbox_update(struct mailbox *box, const struct mailbox_update *update) return box->v.update(box, update); } -static int mailbox_mark_index_deleted(struct mailbox *box, bool del) +int mailbox_mark_index_deleted(struct mailbox *box, bool del) { enum mail_index_transaction_flags trans_flags = 0; struct mail_index_transaction *trans; @@ -737,10 +737,6 @@ int mailbox_delete(struct mailbox *box) } } - if (box->opened) { - if (mailbox_mark_index_deleted(box, TRUE) < 0) - return -1; - } ret = box->v.delete(box); box->deleting = FALSE; diff --git a/src/plugins/lazy-expunge/lazy-expunge-plugin.c b/src/plugins/lazy-expunge/lazy-expunge-plugin.c index 784def5d1d..9513d23d67 100644 --- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c +++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c @@ -373,8 +373,11 @@ static int lazy_expunge_mailbox_delete(struct mailbox *box) char timestamp[256]; int ret; - if (llist->internal_namespace) + if (llist->internal_namespace || !box->opened) { + /* a) deleting mailbox from lazy_expunge namespaces + b) deleting a \noselect mailbox */ return lbox->super.delete(box); + } expunge_ns = get_lazy_ns(list->ns->user, LAZY_NAMESPACE_EXPUNGE); dest_ns = get_lazy_ns(list->ns->user, LAZY_NAMESPACE_DELETE); @@ -393,7 +396,11 @@ static int lazy_expunge_mailbox_delete(struct mailbox *box) destname = t_strconcat(box->name, "-", timestamp, NULL); } - /* first move the actual mailbox */ + /* avoid potential race conditions by marking it deleted */ + if (mailbox_mark_index_deleted(box, TRUE) < 0) + return -1; + + /* rename it into the lazy_expunge namespace */ ret = mailbox_move(box, dest_ns->list, destname, &expunge_box); if (ret < 0) return -1; -- 2.47.3