dovecot-2.1: lib-index: Fixed handling of finding a duplicate do...

dovecot at dovecot.org dovecot at dovecot.org
Thu Oct 18 06:00:31 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/be50d12be960
changeset: 14770:be50d12be960
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Oct 18 06:00:18 2012 +0300
description:
lib-index: Fixed handling of finding a duplicate dovecot.index.log file_seq
Previously we assumed that the already opened file was always the wrong one,
but more common was that the newly opened file was .log.2 which should have
been deleted.

diffstat:

 src/lib-index/mail-transaction-log-file.c |  47 +++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 17 deletions(-)

diffs (67 lines):

diff -r bcef97fb1202 -r be50d12be960 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Thu Oct 18 05:55:30 2012 +0300
+++ b/src/lib-index/mail-transaction-log-file.c	Thu Oct 18 06:00:18 2012 +0300
@@ -443,6 +443,32 @@
 }
 
 static int
+mail_transaction_log_file_fail_dupe(struct mail_transaction_log_file *file)
+{
+	int ret;
+
+	/* mark the old file corrupted. we can't safely remove
+	   it from the list however, so return failure. */
+	file->hdr.indexid = 0;
+	if (strcmp(file->filepath, file->log->head->filepath) != 0) {
+		/* only mark .2 corrupted, just to make sure we don't lose any
+		   changes from .log in case we're somehow wrong */
+		mail_transaction_log_mark_corrupted(file);
+		ret = 0;
+	} else {
+		ret = -1;
+	}
+	if (!file->corrupted) {
+		file->corrupted = TRUE;
+		mail_index_set_error(file->log->index,
+				     "Transaction log %s: "
+				     "duplicate transaction log sequence (%u)",
+				     file->filepath, file->hdr.file_seq);
+	}
+	return ret;
+}
+
+static int
 mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file,
 				   bool ignore_estale)
 {
@@ -528,26 +554,13 @@
 	   corrupted. */
 	for (f = file->log->files; f != NULL; f = f->next) {
 		if (f->hdr.file_seq == file->hdr.file_seq) {
-			/* mark the old file corrupted. we can't safely remove
-			   it from the list however, so return failure. */
-			f->hdr.indexid = 0;
 			if (strcmp(f->filepath, f->log->head->filepath) != 0) {
-				/* only mark .2 corrupted, just to make sure
-				   we don't lose any changes from .log in case
-				   we're somehow wrong */
-				mail_transaction_log_mark_corrupted(f);
-				ret = 0;
+				/* old "f" is the .log.2 */
+				return mail_transaction_log_file_fail_dupe(f);
 			} else {
-				ret = -1;
+				/* new "file" is probably the .log.2 */
+				return mail_transaction_log_file_fail_dupe(file);
 			}
-			if (!f->corrupted) {
-				f->corrupted = TRUE;
-				mail_index_set_error(f->log->index,
-					"Transaction log %s: "
-					"duplicate transaction log sequence (%u)",
-					f->filepath, f->hdr.file_seq);
-			}
-			return ret;
 		}
 	}
 


More information about the dovecot-cvs mailing list