]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fixed handling of finding a duplicate dovecot.index.log file_seq
authorTimo Sirainen <tss@iki.fi>
Thu, 18 Oct 2012 03:00:18 +0000 (06:00 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 18 Oct 2012 03:00:18 +0000 (06:00 +0300)
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.

src/lib-index/mail-transaction-log-file.c

index d0fd6224340fac8cde2eb9a9c9fa85831815f9cb..a7bdf3988d78e76c57d8f78308e9e790f8aa6013 100644 (file)
@@ -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;
                }
        }