]> 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>
Tue, 25 Apr 2023 07:52:36 +0000 (09:52 +0200)
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 cbf5de30df5cee95750d1476cc3dac604e6df9c5..53b853be3971d73420eb7e88119e8aa647d621e4 100644 (file)
@@ -261,31 +261,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->list, box_path,
-                                   last_temp_file_scan, path_ctime)) {
+       if (dbox_cleanup_temp_files(box->list, 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 af085df6babf9e1aefc5a01518a6f593038d821c..ca8c8353058d9ffefeacd568876368bdd44965a7 100644 (file)
@@ -74,6 +74,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 e7e7f600e500597c1b61e0b6b674abfc09358b6e..8148f72c873cacb795d458ce5aa942c3c5148519 100644 (file)
@@ -201,7 +201,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 5a6fcaddec005a6fd297e3e671caf67a03e9cfaa..d05343cca65e68afa36e01b2c6ce6807df461038 100644 (file)
@@ -376,7 +376,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