]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: dbox_mailbox_open() - Move dbox_cleanup_temp_files() to dbox_mailbox_close()
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 28 Feb 2023 11:21:10 +0000 (11:21 +0000)
committermarkus.valentin <markus.valentin@open-xchange.com>
Fri, 10 Mar 2023 10:51:41 +0000 (10:51 +0000)
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-common/dbox-storage.h
src/lib-storage/index/dbox-multi/mdbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.c

index bacba6538672cba9fa811dca35ff2ba8e3d0adcd..2b546f8477834ff948c2980f0a61a0e5c0ccce87 100644 (file)
@@ -264,31 +264,56 @@ int dbox_mailbox_check_existence(struct mailbox *box, time_t *path_ctime_r)
        }
 }
 
-int dbox_mailbox_open(struct mailbox *box, time_t path_ctime)
+int dbox_mailbox_open(struct mailbox *box, time_t path_ctime ATTR_UNUSED)
 {
-       const char *box_path = mailbox_get_path(box);
-
        if (index_storage_mailbox_open(box, FALSE) < 0)
                return -1;
        mail_index_set_fsync_mode(box->index,
                                  box->storage->set->parsed_fsync_mode,
                                  MAIL_INDEX_FSYNC_MASK_APPENDS |
                                  MAIL_INDEX_FSYNC_MASK_EXPUNGES);
+       return 0;
+}
+
+static void dbox_mailbox_close_cleanup(struct mailbox *box)
+{
+       if (box->view == NULL)
+               return;
+
+       const struct mail_index_header *hdr =
+               mail_index_get_header(box->view);
+
+       const char *box_path = mailbox_get_path(box);
+       time_t scan_time = hdr->last_temp_file_scan;
+       time_t change_time = -1;
 
-       const struct mail_index_header *hdr = mail_index_get_header(box->view);
-       uint32_t last_temp_file_scan = hdr->last_temp_file_scan;
-       if (last_temp_file_scan == 0) {
+       if (scan_time == 0) {
+               /* Try to fetch the scan time from dhe directory's atime
+                  if the directory exists. In case, get also the ctime */
                struct stat stats;
-               if (stat(box_path, &stats) == 0)
-                       last_temp_file_scan = stats.st_atim.tv_sec;
+               if (stat(box_path, &stats) == 0) {
+                       scan_time = stats.st_atim.tv_sec;
+                       change_time = stats.st_ctim.tv_sec;
+               } else {
+                       if (errno != ENOENT) {
+                               e_error(box->event,
+                                       "stat(%s) failed: %m", box_path);
+                       }
+                       return;
+               }
        }
 
-       if (dbox_cleanup_temp_files(box, box_path,
-                                   last_temp_file_scan, path_ctime)) {
+       if (dbox_cleanup_temp_files(box, box_path, scan_time, change_time) ||
+               hdr->last_temp_file_scan == 0) {
                /* temp files were scanned. update the last scan timestamp. */
                index_mailbox_update_last_temp_file_scan(box);
        }
-       return 0;
+}
+
+void dbox_mailbox_close(struct mailbox *box)
+{
+       dbox_mailbox_close_cleanup(box);
+       index_storage_mailbox_close(box);
 }
 
 static int dir_is_empty(struct mail_storage *storage, const char *path)
index 8e1aee28f25c2aa71fb5e458723057fde5304300..248f5294d69b43871c70ff025fc38c818d7f1c9a 100644 (file)
@@ -73,6 +73,7 @@ uint32_t dbox_get_uidvalidity_next(struct mailbox_list *list);
 void dbox_notify_changes(struct mailbox *box);
 int dbox_mailbox_check_existence(struct mailbox *box, time_t *path_ctime_r);
 int dbox_mailbox_open(struct mailbox *box, time_t path_ctime);
+void dbox_mailbox_close(struct mailbox *box);
 int dbox_mailbox_create(struct mailbox *box,
                        const struct mailbox_update *update, bool directory);
 int dbox_mailbox_create_indexes(struct mailbox *box,
index edaa236016c3760335c089447d9978fb3dde9b0e..76c30619ec5e8cebcd3bc758695c1739cca2020b 100644 (file)
@@ -205,7 +205,7 @@ static void mdbox_mailbox_close(struct mailbox *box)
        if (mstorage->corrupted && !mstorage->rebuilding_storage)
                (void)mdbox_storage_rebuild(mstorage);
 
-       index_storage_mailbox_close(box);
+       dbox_mailbox_close(box);
 }
 
 int mdbox_read_header(struct mdbox_mailbox *mbox,
index cfa439549dc7007300ad3cec784941ad837cdf31..cc0782d2bd1ba7499cbc9007e59e40f126c36b81 100644 (file)
@@ -375,7 +375,8 @@ static void sdbox_mailbox_close(struct mailbox *box)
 
        if (mbox->corrupted_rebuild_count != 0)
                (void)sdbox_sync(mbox, 0);
-       index_storage_mailbox_close(box);
+
+       dbox_mailbox_close(box);
 }
 
 static int