dovecot-2.0: lib-storage: If mailbox deletion crashed, undelete ...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Apr 9 13:05:05 EEST 2012
details: http://hg.dovecot.org/dovecot-2.0/rev/777f393ba12f
changeset: 13083:777f393ba12f
user: Timo Sirainen <tss at iki.fi>
date: Mon Apr 09 13:04:59 2012 +0300
description:
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
The deletion is assumed to be crashed if it was started over 5 minutes ago.
diffstat:
src/lib-storage/mail-storage.c | 59 +++++++++++++++++++++--------------------
1 files changed, 30 insertions(+), 29 deletions(-)
diffs (85 lines):
diff -r ae2802b68594 -r 777f393ba12f src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c Mon Apr 09 11:47:13 2012 +0300
+++ b/src/lib-storage/mail-storage.c Mon Apr 09 13:04:59 2012 +0300
@@ -632,9 +632,37 @@
return 0;
}
+static bool mailbox_try_undelete(struct mailbox *box)
+{
+ time_t mtime;
+
+ if (mail_index_get_modification_time(box->index, &mtime) < 0)
+ return FALSE;
+ if (mtime + MAILBOX_DELETE_RETRY_SECS > time(NULL))
+ return FALSE;
+
+ if (mailbox_mark_index_deleted(box, FALSE) < 0)
+ return FALSE;
+ box->mailbox_deleted = FALSE;
+ return TRUE;
+}
+
int mailbox_open(struct mailbox *box)
{
- return mailbox_open_full(box, NULL);
+ if (mailbox_open_full(box, NULL) < 0) {
+ if (!box->mailbox_deleted)
+ return -1;
+
+ /* mailbox has been marked as deleted. if this deletion
+ started (and crashed) a long time ago, it can be confusing
+ to user that the mailbox can't be opened. so we'll just
+ undelete it and reopen. */
+ if(!mailbox_try_undelete(box))
+ return -1;
+ if (mailbox_open_full(box, NULL) < 0)
+ return -1;
+ }
+ return 0;
}
int mailbox_open_stream(struct mailbox *box, struct istream *input)
@@ -757,21 +785,6 @@
return 0;
}
-static bool mailbox_try_undelete(struct mailbox *box)
-{
- time_t mtime;
-
- if (mail_index_get_modification_time(box->index, &mtime) < 0)
- return FALSE;
- if (mtime + MAILBOX_DELETE_RETRY_SECS > time(NULL))
- return FALSE;
-
- if (mailbox_mark_index_deleted(box, FALSE) < 0)
- return FALSE;
- box->mailbox_deleted = FALSE;
- return TRUE;
-}
-
int mailbox_delete(struct mailbox *box)
{
enum mail_error error;
@@ -788,19 +801,7 @@
(void)mail_storage_get_last_error(box->storage, &error);
if (error != MAIL_ERROR_NOTFOUND)
return -1;
- if (!box->mailbox_deleted) {
- /* \noselect mailbox */
- } else {
- /* if deletion happened a long time ago, it means it
- crashed while doing it. undelete the mailbox in
- that case. */
- if (!mailbox_try_undelete(box))
- return -1;
-
- /* retry */
- if (mailbox_open(box) < 0)
- return -1;
- }
+ /* \noselect mailbox */
}
ret = box->v.delete(box);
More information about the dovecot-cvs
mailing list