changeset 2140:e2cd51b99359 HEAD

"readonly sync" -> "forced sync"
author Timo Sirainen <tss@iki.fi>
date Wed, 16 Jun 2004 03:53:37 +0300
parents 9f90f83835ae
children 8690d2000e33
files src/lib-storage/index/maildir/maildir-storage.h src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/maildir/maildir-util.c
diffstat 3 files changed, 21 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-storage.h	Wed Jun 16 03:49:51 2004 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Wed Jun 16 03:53:37 2004 +0300
@@ -39,7 +39,7 @@
 maildir_mailbox_list_next(struct mailbox_list_context *ctx);
 
 int maildir_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
-int maildir_storage_sync_readonly(struct index_mailbox *ibox);
+int maildir_storage_sync_force(struct index_mailbox *ibox);
 
 struct mailbox_transaction_context *
 maildir_transaction_begin(struct mailbox *box, int hide);
--- a/src/lib-storage/index/maildir/maildir-sync.c	Wed Jun 16 03:49:51 2004 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Wed Jun 16 03:53:37 2004 +0300
@@ -824,15 +824,19 @@
 	return ret;
 }
 
-static int maildir_sync_context(struct maildir_sync_context *ctx)
+static int maildir_sync_context(struct maildir_sync_context *ctx, int forced)
 {
 	int ret, new_changed, cur_changed;
 
-	if (maildir_sync_quick_check(ctx, &new_changed, &cur_changed) < 0)
-		return -1;
+	if (!forced) {
+		if (maildir_sync_quick_check(ctx, &new_changed, &cur_changed) < 0)
+			return -1;
 
-	if (!new_changed && !cur_changed)
-		return 0;
+		if (!new_changed && !cur_changed)
+			return 0;
+	} else {
+		new_changed = cur_changed = TRUE;
+	}
 
 	/* we have to lock uidlist immediately, otherwise there's race
 	   conditions with other processes who might write older maildir
@@ -840,8 +844,14 @@
 
 	   alternative would be to lock it when new files are found, but
 	   the directory scans _must_ be restarted then */
-	if ((ret = maildir_uidlist_try_lock(ctx->ibox->uidlist)) <= 0)
+	if ((ret = maildir_uidlist_try_lock(ctx->ibox->uidlist)) < 0)
 		return ret;
+	if (ret == 0 && !forced) {
+		/* we didn't get a lock, don't do syncing unless we really
+		   want to check for expunges or renames. new files won't
+		   be added. */
+		return 0;
+	}
 
 	ctx->partial = !cur_changed;
 	ctx->uidlist_sync_ctx =
@@ -865,32 +875,13 @@
 	return ret;
 }
 
-static int maildir_sync_context_readonly(struct maildir_sync_context *ctx)
-{
-	int ret;
-
-	ctx->uidlist_sync_ctx =
-		maildir_uidlist_sync_init(ctx->ibox->uidlist, FALSE);
-
-	if (maildir_scan_dir(ctx, TRUE) < 0)
-		return -1;
-	if (maildir_scan_dir(ctx, FALSE) < 0)
-		return -1;
-
-	maildir_uidlist_sync_finish(ctx->uidlist_sync_ctx);
-	ret = maildir_uidlist_sync_deinit(ctx->uidlist_sync_ctx);
-        ctx->uidlist_sync_ctx = NULL;
-
-	return ret;
-}
-
-int maildir_storage_sync_readonly(struct index_mailbox *ibox)
+int maildir_storage_sync_force(struct index_mailbox *ibox)
 {
         struct maildir_sync_context *ctx;
 	int ret;
 
 	ctx = maildir_sync_context_new(ibox);
-	ret = maildir_sync_context_readonly(ctx);
+	ret = maildir_sync_context(ctx, TRUE);
 	maildir_sync_deinit(ctx);
 	return ret;
 }
@@ -906,7 +897,7 @@
 		ibox->sync_last_check = ioloop_time;
 
 		ctx = maildir_sync_context_new(ibox);
-		ret = maildir_sync_context(ctx);
+		ret = maildir_sync_context(ctx, FALSE);
 		maildir_sync_deinit(ctx);
 
 		if (ret < 0)
--- a/src/lib-storage/index/maildir/maildir-util.c	Wed Jun 16 03:49:51 2004 +0300
+++ b/src/lib-storage/index/maildir/maildir-util.c	Wed Jun 16 03:53:37 2004 +0300
@@ -49,7 +49,7 @@
 		/* file is either renamed or deleted. sync the maildir and
 		   see which one. if file appears to be renamed constantly,
 		   don't try to open it more than 10 times. */
-		if (maildir_storage_sync_readonly(ibox) < 0)
+		if (maildir_storage_sync_force(ibox) < 0)
 			return -1;
 
 		ret = maildir_file_do_try(ibox, uid, func, context);