]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Split off dbox_mailbox_list_cleanup()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 20 Jun 2023 15:54:49 +0000 (18:54 +0300)
committermarkus.valentin <markus.valentin@open-xchange.com>
Wed, 21 Jun 2023 12:46:57 +0000 (12:46 +0000)
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-common/dbox-storage.h

index b54d5117353a454b8ac5ad70da47b07a6950509e..be95ea1f143faebfcfc17eefec069687cf409029 100644 (file)
@@ -174,11 +174,11 @@ void dbox_notify_changes(struct mailbox *box)
        }
 }
 
-static time_t cleanup_interval(struct mailbox *box)
+static time_t cleanup_interval(struct mailbox_list *list)
 {
-       time_t interval = box->list->mail_set->mail_temp_scan_interval;
+       time_t interval = list->mail_set->mail_temp_scan_interval;
 
-       const char *username = box->storage->user->username;
+       const char *username = list->ns->user->username;
        /* No need for a cryptographic-quality hash here. */
        unsigned int hash = crc32_str(username);
 
@@ -188,11 +188,11 @@ static time_t cleanup_interval(struct mailbox *box)
 }
 
 static bool
-dbox_cleanup_temp_files(struct mailbox *box, const char *path,
+dbox_cleanup_temp_files(struct mailbox_list *list, const char *path,
                        time_t last_scan_time, time_t last_change_time)
 {
        /* check once in a while if there are temp files to clean up */
-       time_t interval = cleanup_interval(box);
+       time_t interval = cleanup_interval(list);
        if (interval == 0) {
                /* disabled */
                return FALSE;
@@ -210,7 +210,7 @@ dbox_cleanup_temp_files(struct mailbox *box, const char *path,
                struct stat st;
                if (stat(path, &st) < 0) {
                        if (errno != ENOENT)
-                               e_error(box->event,
+                               e_error(list->ns->user->event,
                                        "stat(%s) failed: %m", path);
                        return FALSE;
                }
@@ -226,7 +226,7 @@ dbox_cleanup_temp_files(struct mailbox *box, const char *path,
                return stated;
        }
 
-       const char *prefix = mailbox_list_get_global_temp_prefix(box->list);
+       const char *prefix = mailbox_list_get_global_temp_prefix(list);
        (void)unlink_old_files(path, prefix, ioloop_time - DBOX_TMP_DELETE_SECS);
        return TRUE;
 }
@@ -285,39 +285,45 @@ int dbox_mailbox_open(struct mailbox *box)
        return 0;
 }
 
-void dbox_mailbox_close_cleanup(struct mailbox *box)
+int dbox_mailbox_list_cleanup(struct mailbox_list *list, const char *path,
+                             time_t last_temp_file_scan)
 {
-       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;
 
-       if (scan_time == 0) {
-               /* Try to fetch the scan time from dhe directory's atime
+       if (last_temp_file_scan == 0) {
+               /* Try to fetch the scan time from the directory's atime
                   if the directory exists. In case, get also the ctime */
                struct stat stats;
-               if (stat(box_path, &stats) == 0) {
-                       scan_time = stats.st_atim.tv_sec;
+               if (stat(path, &stats) == 0) {
+                       last_temp_file_scan = 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);
+                               e_error(list->ns->user->event,
+                                       "stat(%s) failed: %m", path);
                        }
-                       return;
+                       return -1;
                }
        }
 
-       if (dbox_cleanup_temp_files(box, box_path, scan_time, change_time) ||
-               hdr->last_temp_file_scan == 0) {
+       if (dbox_cleanup_temp_files(list, path, last_temp_file_scan, change_time) ||
+           last_temp_file_scan == 0) {
                /* temp files were scanned. update the last scan timestamp. */
-               index_mailbox_update_last_temp_file_scan(box);
+               return 1;
        }
+       return 0;
+}
+
+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);
+       if (dbox_mailbox_list_cleanup(box->list, mailbox_get_path(box),
+                                     hdr->last_temp_file_scan) > 0)
+               index_mailbox_update_last_temp_file_scan(box);
 }
 
 void dbox_mailbox_close(struct mailbox *box)
index 6ec670d5d142241d9f3d600fdd730cdd094ace6d..1476778a0b4df01315a078a28a83f7b7544b0a4a 100644 (file)
@@ -77,6 +77,8 @@ int dbox_mailbox_check_existence(struct mailbox *box);
 int dbox_mailbox_open(struct mailbox *box);
 void dbox_mailbox_close(struct mailbox *box);
 void dbox_mailbox_close_cleanup(struct mailbox *box);
+int dbox_mailbox_list_cleanup(struct mailbox_list *list, const char *path,
+                             time_t last_temp_file_scan);
 int dbox_mailbox_create(struct mailbox *box,
                        const struct mailbox_update *update, bool directory);
 int dbox_mailbox_create_indexes(struct mailbox *box,