]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_transaction_log_view_set() - Return -1 only on I/O error
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 10 Aug 2020 14:12:32 +0000 (17:12 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 23 Nov 2020 13:19:54 +0000 (13:19 +0000)
The callers that care about the difference:

 * mail_index_sync_map() already assumes that -1 means I/O error
 * mail_index_sync_set_log_view() handles 0 by logging an error and fscking
   the index, which is likely better than just returning failure.
 * view_sync_set_log_view_range()'s caller handles 0 by rebuilding the
   missing changes in memory. So returning 0 makes it work better.
 * dsync_log_set() and mailbox_get_expunges_init() have fallbacks for
   handling 0, while -1 would just return an error.

src/lib-index/mail-transaction-log-view.c
src/lib-index/mail-transaction-log.h
src/lib-index/test-mail-transaction-log-view.c

index 6efd18e1d6390ec3db64c445330d54a9aa248742..89007135e2ce798fb48c7f9ae1ac9267fb617d51 100644 (file)
@@ -93,7 +93,7 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                /* transaction log is closed already. this log view shouldn't
                   be used anymore. */
                *reason_r = "Log already closed";
-               return -1;
+               return 0;
        }
 
        if (min_file_seq == 0) {
@@ -151,7 +151,7 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                        ") > max_file_offset (%"PRIuUOFF_T")",
                        min_file_seq, min_file_offset, max_file_offset);
                mail_transaction_log_view_set_corrupted(view, "%s", *reason_r);
-               return -1;
+               return 0;
        }
 
        view->tail = view->head = file = NULL;
@@ -239,7 +239,7 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                        ") < hdr_size (%u)",
                        min_file_seq, min_file_offset, view->tail->hdr.hdr_size);
                mail_transaction_log_view_set_corrupted(view, "%s", *reason_r);
-               return -1;
+               return 0;
        }
        if (max_file_offset < view->head->hdr.hdr_size) {
                /* log file offset is probably corrupted in the index file. */
@@ -248,7 +248,7 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                        ") < hdr_size (%u)",
                        max_file_seq, max_file_offset, view->head->hdr.hdr_size);
                mail_transaction_log_view_set_corrupted(view, "%s", *reason_r);
-               return -1;
+               return 0;
        }
 
        /* we have all of them. update refcounts. */
@@ -314,7 +314,7 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                        ") > sync_offset (%"PRIuUOFF_T")", min_file_seq,
                        min_file_offset, view->head->sync_offset);
                mail_transaction_log_view_set_corrupted(view, "%s", *reason_r);
-               return -1;
+               return 0;
        }
 
        i_assert(max_file_seq == (uint32_t)-1 ||
@@ -335,9 +335,10 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
        view->max_file_offset = I_MIN(max_file_offset, view->head->sync_offset);
        view->broken = FALSE;
 
-       if (mail_transaction_log_file_get_highest_modseq_at(view->cur,
-                               view->cur_offset, &view->prev_modseq, reason_r) <= 0)
-               return -1;
+       ret = mail_transaction_log_file_get_highest_modseq_at(view->cur,
+               view->cur_offset, &view->prev_modseq, reason_r);
+       if (ret <= 0)
+               return ret;
 
        i_assert(view->cur_offset <= view->cur->sync_offset);
        return 1;
index c977361a5f8f3d84e624b65b575c02d1b91c4626..8469512dc4f2b31c5bfbf4ce8410599cec7b7586 100644 (file)
@@ -233,9 +233,9 @@ struct mail_transaction_log_view *
 mail_transaction_log_view_open(struct mail_transaction_log *log);
 void mail_transaction_log_view_close(struct mail_transaction_log_view **view);
 
-/* Set view boundaries. Returns -1 if error, 0 if files are lost or corrupted,
-   1 if ok. reset_r=TRUE if the whole index should be reset before applying any
-   changes. */
+/* Set view boundaries. Returns 1 if ok, 0 if files are lost, corrupted or the
+   offsets are broken, -1 if I/O error. reset_r=TRUE if the whole index should
+   be reset before applying any changes. */
 int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                                  uint32_t min_file_seq, uoff_t min_file_offset,
                                  uint32_t max_file_seq, uoff_t max_file_offset,
index e7f480a85eb80267655454532e8b40b23265b02c..24fbc9724a63eef551a7198043e7471fd57d183e 100644 (file)
@@ -219,7 +219,7 @@ static void test_mail_transaction_log_view(void)
 
        test_begin("closed log handling");
        view->log = NULL;
-       test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, UOFF_T_MAX, &reset, &reason) == -1);
+       test_assert(mail_transaction_log_view_set(view, 0, 0, (uint32_t)-1, UOFF_T_MAX, &reset, &reason) == 0);
        view->log = log;
        test_end();