[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-sync.c, 1.66, 1.67

cras at dovecot.org cras at dovecot.org
Sun Sep 18 18:41:41 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-storage/index/maildir
In directory talvi:/tmp/cvs-serv5240

Modified Files:
	maildir-sync.c 
Log Message:
Partial syncs caused index's next_uid to be updated even if the new mails
weren't added to index. That caused some UID corruption errors.



Index: maildir-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-sync.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- maildir-sync.c	18 Sep 2005 12:27:53 -0000	1.66
+++ maildir-sync.c	18 Sep 2005 15:41:38 -0000	1.67
@@ -1056,17 +1056,31 @@
 	maildir_uidlist_iter_deinit(iter);
 	array_free(&keywords);
 
-	if (!partial) {
+	if (partial) {
 		/* expunge the rest */
 		for (seq++; seq <= hdr->messages_count; seq++)
 			mail_index_expunge(trans, seq);
+
+		/* next_uid must be updated only in non-partial syncs since
+		   partial syncs don't add the new mails to index. also we'll
+		   have to do it here before syncing index records, since after
+		   that the uidlist's next_uid value may have changed. */
+		next_uid = maildir_uidlist_get_next_uid(mbox->uidlist);
+		if (next_uid != 0 && hdr->next_uid != next_uid) {
+			mail_index_update_header(trans,
+				offsetof(struct mail_index_header, next_uid),
+				&next_uid, sizeof(next_uid), FALSE);
+		}
 	}
 
-	/* now, sync the index */
-        mbox->syncing_commit = TRUE;
-	if (maildir_sync_index_records(sync_ctx) < 0)
-		ret = -1;
-	mbox->syncing_commit = FALSE;
+	if (!mbox->syncing_commit) {
+		/* now, sync the index. NOTE: may recurse back to here with
+		   partial syncs */
+		mbox->syncing_commit = TRUE;
+		if (maildir_sync_index_records(sync_ctx) < 0)
+			ret = -1;
+		mbox->syncing_commit = FALSE;
+	}
 
 	if (mbox->dirty_cur_time == 0 &&
 	    mbox->last_cur_mtime != (time_t)hdr->sync_stamp) {
@@ -1115,13 +1129,6 @@
 			&uid_validity, sizeof(uid_validity), TRUE);
 	}
 
-	next_uid = maildir_uidlist_get_next_uid(mbox->uidlist);
-	if (next_uid != 0 && hdr->next_uid != next_uid) {
-		mail_index_update_header(trans,
-			offsetof(struct mail_index_header, next_uid),
-			&next_uid, sizeof(next_uid), FALSE);
-	}
-
 	if (ret < 0) {
 		mail_index_transaction_rollback(trans);
 		mail_index_sync_rollback(sync_ctx->sync_ctx);



More information about the dovecot-cvs mailing list