changeset 22314:76a93ccad769

lib-storage: Storage backend sync_init()s no longer need to check if mailbox is open The previous change guarantees it.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 10 Jul 2017 14:20:50 +0300
parents d4f4499c2a3a
children 445b89dc8246
files src/lib-storage/index/cydir/cydir-sync.c src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c src/lib-storage/index/dbox-multi/mdbox-sync.c src/lib-storage/index/dbox-single/sdbox-sync.c src/lib-storage/index/imapc/imapc-sync.c src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/index/pop3c/pop3c-sync.c src/lib-storage/index/raw/raw-sync.c
diffstat 9 files changed, 17 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/cydir/cydir-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -165,12 +165,7 @@
 	struct cydir_mailbox *mbox = (struct cydir_mailbox *)box;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (index_mailbox_want_full_sync(&mbox->box, flags) && ret == 0)
+	if (index_mailbox_want_full_sync(&mbox->box, flags))
 		ret = cydir_sync(mbox);
 
 	return index_mailbox_sync_init(box, flags, ret < 0);
--- a/src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-deleted-storage.c	Mon Jul 10 14:20:50 2017 +0300
@@ -230,13 +230,8 @@
 	enum mdbox_sync_flags mdbox_sync_flags = 0;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (ret == 0 && (index_mailbox_want_full_sync(&mbox->box, flags) ||
-			 mbox->storage->corrupted))
+	if (index_mailbox_want_full_sync(&mbox->box, flags) ||
+	    mbox->storage->corrupted)
 		ret = mdbox_deleted_sync(mbox, mdbox_sync_flags);
 
 	return index_mailbox_sync_init(box, flags, ret < 0);
--- a/src/lib-storage/index/dbox-multi/mdbox-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -359,17 +359,10 @@
 	enum mdbox_sync_flags mdbox_sync_flags = 0;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (box->opened) {
-		if (mail_index_reset_fscked(box->index))
-			mdbox_storage_set_corrupted(mbox->storage);
-	}
-	if (ret == 0 && (index_mailbox_want_full_sync(&mbox->box, flags) ||
-			 mbox->storage->corrupted)) {
+	if (mail_index_reset_fscked(box->index))
+		mdbox_storage_set_corrupted(mbox->storage);
+	if (index_mailbox_want_full_sync(&mbox->box, flags) ||
+	    mbox->storage->corrupted) {
 		if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0)
 			mdbox_sync_flags |= MDBOX_SYNC_FLAG_FORCE_REBUILD;
 		ret = mdbox_sync(mbox, mdbox_sync_flags);
--- a/src/lib-storage/index/dbox-single/sdbox-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -312,15 +312,10 @@
 	enum sdbox_sync_flags sdbox_sync_flags = 0;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (ret == 0 && mail_index_reset_fscked(box->index))
+	if (mail_index_reset_fscked(box->index))
 		sdbox_set_mailbox_corrupted(box);
-	if (ret == 0 && (index_mailbox_want_full_sync(&mbox->box, flags) ||
-			 mbox->corrupted_rebuild_count != 0)) {
+	if (index_mailbox_want_full_sync(&mbox->box, flags) ||
+	    mbox->corrupted_rebuild_count != 0) {
 		if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0)
 			sdbox_sync_flags |= SDBOX_SYNC_FLAG_FORCE_REBUILD;
 		ret = sdbox_sync(mbox, sdbox_sync_flags);
--- a/src/lib-storage/index/imapc/imapc-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/imapc/imapc-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -675,13 +675,7 @@
 			list->refreshed_mailboxes_recently = FALSE;
 	}
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (ret == 0)
-		imapc_noop_if_needed(mbox, flags);
+	imapc_noop_if_needed(mbox, flags);
 
 	if (imapc_mailbox_commit_delayed_trans(mbox, &changes) < 0)
 		ret = -1;
--- a/src/lib-storage/index/maildir/maildir-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -1087,11 +1087,6 @@
 	bool lost_files, force_resync;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			return index_mailbox_sync_init(box, flags, TRUE);
-	}
-
 	force_resync = (flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0;
 	if (index_mailbox_want_full_sync(&mbox->box, flags)) {
 		ret = maildir_sync_run(mbox, flags, force_resync,
--- a/src/lib-storage/index/mbox/mbox-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -2043,12 +2043,7 @@
 	enum mbox_sync_flags mbox_sync_flags = 0;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (index_mailbox_want_full_sync(&mbox->box, flags) && ret == 0) {
+	if (index_mailbox_want_full_sync(&mbox->box, flags)) {
 		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
 		    !mbox->storage->set->mbox_very_dirty_syncs)
 			mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
--- a/src/lib-storage/index/pop3c/pop3c-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/pop3c/pop3c-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -351,18 +351,11 @@
 	struct pop3c_mailbox *mbox = (struct pop3c_mailbox *)box;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	} else {
-		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
-		    mbox->msg_uidls == NULL) {
-			/* FIXME: reconnect */
-		}
+	if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
+	    mbox->msg_uidls == NULL) {
+		/* FIXME: reconnect */
 	}
 
-	if (ret == 0)
-		ret = pop3c_sync(mbox);
-
+	ret = pop3c_sync(mbox);
 	return index_mailbox_sync_init(box, flags, ret < 0);
 }
--- a/src/lib-storage/index/raw/raw-sync.c	Mon Jul 10 14:19:47 2017 +0300
+++ b/src/lib-storage/index/raw/raw-sync.c	Mon Jul 10 14:20:50 2017 +0300
@@ -59,12 +59,7 @@
 	struct raw_mailbox *mbox = (struct raw_mailbox *)box;
 	int ret = 0;
 
-	if (!box->opened) {
-		if (mailbox_open(box) < 0)
-			ret = -1;
-	}
-
-	if (!mbox->synced && ret == 0)
+	if (!mbox->synced)
 		ret = raw_sync(mbox);
 
 	return index_mailbox_sync_init(box, flags, ret < 0);