From 6b0d8106ae51ffc6ce45636b34d2e21cbefca7fd Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 24 Aug 2010 17:00:39 +0100 Subject: [PATCH] lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc. --- src/lib-storage/mail-storage-private.h | 2 ++ src/lib-storage/mail-storage.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 3f32677fd5..68e640e5d9 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -268,6 +268,8 @@ struct mailbox { unsigned int backend_readonly:1; /* Mailbox is being deleted */ unsigned int deleting:1; + /* Mailbox was already marked as deleted within this allocation. */ + unsigned int marked_deleted:1; /* TRUE if this is an INBOX for this user */ unsigned int inbox_user:1; /* TRUE if this is an INBOX for this namespace (user or shared) */ diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 9e810c350e..f1bdc5095f 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -669,6 +669,12 @@ int mailbox_mark_index_deleted(struct mailbox *box, bool del) enum mail_index_transaction_flags trans_flags = 0; struct mail_index_transaction *trans; + if (box->marked_deleted && del) { + /* we already marked it deleted. this allows plugins to + "lock" the deletion earlier. */ + return 0; + } + trans_flags = del ? 0 : MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL; trans = mail_index_transaction_begin(box->view, trans_flags); if (del) @@ -683,7 +689,11 @@ int mailbox_mark_index_deleted(struct mailbox *box, bool del) /* sync the mailbox. this finishes the index deletion and it can succeed only for a single session. we do it here, so the rest of the deletion code doesn't have to worry about race conditions. */ - return mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ); + if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) + return -1; + + box->marked_deleted = del; + return 0; } static bool mailbox_try_undelete(struct mailbox *box) -- 2.47.3