From: Timo Sirainen Date: Thu, 18 Oct 2012 03:00:18 +0000 (+0300) Subject: lib-index: Fixed handling of finding a duplicate dovecot.index.log file_seq X-Git-Tag: 2.2.alpha1~20^2~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4fcee755029b42c1f31227211290fa5047c00075;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-index/mail-transaction-log-file.c b/src/lib-index/mail-transaction-log-file.c index d0fd622434..a7bdf3988d 100644 --- a/src/lib-index/mail-transaction-log-file.c +++ b/src/lib-index/mail-transaction-log-file.c @@ -442,6 +442,32 @@ mail_transaction_log_file_read_header(struct mail_transaction_log_file *file) return ret < 0 ? -1 : (ssize_t)pos; } +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 @@ mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file, 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; - } - 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); + /* new "file" is probably the .log.2 */ + return mail_transaction_log_file_fail_dupe(file); } - return ret; } }