]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_index_reopen_if_changed() - Add reopened_r parameter
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 10 Aug 2020 15:00:09 +0000 (18:00 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 23 Nov 2020 13:19:55 +0000 (13:19 +0000)
src/lib-index/mail-index-map-read.c
src/lib-index/mail-index-private.h
src/lib-index/mail-index.c

index 1fcd6699eed51ecd3c9beac92372c464ede84555..e584eaedc9f70d5bd5a305deb8f5daad35af6ee6 100644 (file)
@@ -307,14 +307,14 @@ mail_index_map_latest_file(struct mail_index *index, const char **reason_r)
        struct mail_index_map *old_map, *new_map;
        struct stat st;
        uoff_t file_size;
-       bool use_mmap, unusable = FALSE;
+       bool use_mmap, reopened, unusable = FALSE;
        const char *error;
        int ret, try;
 
        *reason_r = NULL;
 
        index->reopen_main_index = FALSE;
-       ret = mail_index_reopen_if_changed(index, reason_r);
+       ret = mail_index_reopen_if_changed(index, &reopened, reason_r);
        if (ret <= 0) {
                if (ret < 0)
                        return -1;
index ea1cf393db49690e8e2ce877182b2dca12404cd5..e523e4dfded2ba282ea1cbb940cf091bb5456e7b 100644 (file)
@@ -250,7 +250,10 @@ int mail_index_create_tmp_file(struct mail_index *index,
 
 int mail_index_try_open_only(struct mail_index *index);
 void mail_index_close_file(struct mail_index *index);
-int mail_index_reopen_if_changed(struct mail_index *index,
+/* Returns 1 if index was successfully (re-)opened, 0 if the index no longer
+   exists, -1 if I/O error. If 1 is returned, reopened_r=TRUE if a new index
+   was actually reopened (or if index wasn't even open before this call). */
+int mail_index_reopen_if_changed(struct mail_index *index, bool *reopened_r,
                                 const char **reason_r);
 /* Update/rewrite the main index file from index->map */
 void mail_index_write(struct mail_index *index, bool want_rotate,
index 0ef4bebd799e50a593760a9046d318f611c1a549..cf2d4c7e7248ffd64c99b9c7792b7579508b0488 100644 (file)
@@ -815,12 +815,14 @@ int mail_index_unlink(struct mail_index *index)
        }
 }
 
-int mail_index_reopen_if_changed(struct mail_index *index,
+int mail_index_reopen_if_changed(struct mail_index *index, bool *reopened_r,
                                 const char **reason_r)
 {
        struct stat st1, st2;
        int ret;
 
+       *reopened_r = FALSE;
+
        if (MAIL_INDEX_IS_IN_MEMORY(index)) {
                *reason_r = "in-memory index";
                return 0;
@@ -863,8 +865,10 @@ int mail_index_reopen_if_changed(struct mail_index *index,
 final:
        if ((ret = mail_index_try_open_only(index)) == 0)
                *reason_r = "index not found via open()";
-       else if (ret > 0)
+       else if (ret > 0) {
                *reason_r = "index opened";
+               *reopened_r = TRUE;
+       }
        return ret;
 }