]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fix accessing the same "raw" mailbox multiple times in process.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 14 Jan 2017 13:10:17 +0000 (15:10 +0200)
committerGitLab <gitlab@git.dovecot.net>
Sat, 14 Jan 2017 15:18:41 +0000 (17:18 +0200)
If the same file was opened as the raw mailbox multiple times, the previous
mail_index was cached by mail-index-alloc-cache. Opening it the second time
already contained a mail in the index, so trying to add another one logged
an error:

Error: Log synchronization error at seq=1,offset=256 for (in-memory index): Append with UID 1, but next_uid = 2

src/lib-storage/index/raw/raw-sync.c

index 0a28ccecaf405555a575da08b1e5e70cc5aeebab..ea6402dceadbd6b7581785a457065a709f41c979 100644 (file)
@@ -22,6 +22,12 @@ static int raw_sync(struct raw_mailbox *mbox)
                MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY |
                MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES;
 
+       if (mail_index_view_get_messages_count(mbox->box.view) > 0) {
+               /* already-synced index was opened via
+                  mail-index-alloc-cache. */
+               return 0;
+       }
+
        ret = mail_index_sync_begin(mbox->box.index, &index_sync_ctx,
                                    &sync_view, &trans, sync_flags);
        if (ret <= 0) {