dovecot-2.1: lib-storage: If mailbox deletion crashed, undelete ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 9 13:04:37 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/a109580dea25
changeset: 14400:a109580dea25
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 09 13:04:19 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 30f8ef8696f0 -r a109580dea25 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Tue Apr 03 14:45:10 2012 +0300
+++ b/src/lib-storage/mail-storage.c	Mon Apr 09 13:04:19 2012 +0300
@@ -914,9 +914,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)
@@ -1043,21 +1071,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)
 {
 	int ret;
@@ -1077,19 +1090,7 @@
 	if (mailbox_open(box) < 0) {
 		if (mailbox_get_last_mail_error(box) != 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