]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Try harder to open index with MAIL_INDEX_OPEN_FLAG_READONLY
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 1 Apr 2021 14:24:10 +0000 (17:24 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 7 May 2021 08:29:16 +0000 (08:29 +0000)
The readonly-flag is used when rebuilding index or dumping indexes.
In both cases it's better to try to open the index as best as possible,
since fsck isn't allowed.

src/lib-index/mail-index-map-read.c
src/lib-index/mail-index.c

index 12500f393d212c73fe79fb7b88956fc235aef159..9a8b3341c71c742d075e37b4bfd3def8e987d3ad 100644 (file)
@@ -445,8 +445,10 @@ mail_index_map_latest_sync(struct mail_index *index,
                                     "(reopen_reason: %s)",
                                     index->filepath, reason, map_reason,
                                     reopen_reason);
-               if (mail_index_fsck(index) < 0)
-                       return -1;
+               if (!index->readonly) {
+                       if (mail_index_fsck(index) < 0)
+                               return -1;
+               }
        }
 
        ret = mail_index_map_latest_file(index, &reason);
index 809547ed494cf6f65a6aef568948709ba05ad506..9796c394be57e49297ac5e0fb6d75f7073df04c6 100644 (file)
@@ -507,7 +507,7 @@ mail_index_try_open(struct mail_index *index)
                return 0;
 
        ret = mail_index_map(index, MAIL_INDEX_SYNC_HANDLER_HEAD);
-       if (ret == 0) {
+       if (ret == 0 && !index->readonly) {
                /* it's corrupted - recreate it */
                if (index->fd != -1) {
                        if (close(index->fd) < 0)
@@ -596,7 +596,7 @@ static int mail_index_open_files(struct mail_index *index,
        }
        if (ret >= 0) {
                ret = index->map != NULL ? 1 : mail_index_try_open(index);
-               if (ret == 0) {
+               if (ret == 0 && !index->readonly) {
                        /* corrupted */
                        mail_transaction_log_close(index->log);
                        ret = mail_transaction_log_create(index->log, TRUE);