]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox: Use mail_index_header.last_temp_file_scan instead of directory's atime
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 28 Jun 2017 16:46:01 +0000 (19:46 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 3 Jul 2017 12:25:27 +0000 (15:25 +0300)
This will be required for the following ITERINDEX change.

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 add4522b7c9bf8e3453c448bf51e7bc4a588e8e1..463fdb18e829fbd1841a732ac1ba9d803da1e19a 100644 (file)
@@ -164,7 +164,7 @@ void dbox_notify_changes(struct mailbox *box)
        }
 }
 
-static void
+static bool
 dbox_cleanup_temp_files(struct mailbox_list *list, const char *path,
                        time_t last_scan_time, time_t last_change_time)
 {
@@ -173,29 +173,32 @@ dbox_cleanup_temp_files(struct mailbox_list *list, const char *path,
        /* check once in a while if there are temp files to clean up */
        if (interval == 0) {
                /* disabled */
+               return FALSE;
        } else if (last_scan_time >= ioloop_time - (time_t)interval) {
                /* not the time to scan it yet */
+               return FALSE;
        } else {
                if (last_scan_time > last_change_time + DBOX_TMP_DELETE_SECS) {
                        /* there haven't been any changes to this directory
                           since we last checked it. */
-                       return;
+                       return FALSE;
                }
                const char *prefix =
                        mailbox_list_get_global_temp_prefix(list);
                (void)unlink_old_files(path, prefix,
                                       ioloop_time - DBOX_TMP_DELETE_SECS);
+               return TRUE;
        }
 }
 
-int dbox_mailbox_check_existence(struct mailbox *box)
+int dbox_mailbox_check_existence(struct mailbox *box, time_t *path_ctime_r)
 {
        const char *box_path = mailbox_get_path(box);
        struct stat st;
 
        if (stat(box_path, &st) == 0) {
-               dbox_cleanup_temp_files(box->list, box_path,
-                                       st.st_atime, st.st_ctime);
+               *path_ctime_r = st.st_ctime;
+               return 0;
        } else if (errno == ENOENT || errno == ENAMETOOLONG) {
                mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
                        T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname));
@@ -209,17 +212,25 @@ int dbox_mailbox_check_existence(struct mailbox *box)
                                          "stat(%s) failed: %m", box_path);
                return -1;
        }
-       return 0;
 }
 
-int dbox_mailbox_open(struct mailbox *box)
+int dbox_mailbox_open(struct mailbox *box, time_t path_ctime)
 {
+       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);
+
+       const struct mail_index_header *hdr = mail_index_get_header(box->view);
+       if (dbox_cleanup_temp_files(box->list, box_path,
+                                   hdr->last_temp_file_scan, path_ctime)) {
+               /* temp files were scanned. update the last scan timestamp. */
+               index_mailbox_update_last_temp_file_scan(box);
+       }
        return 0;
 }
 
index f6117a27b17fb95297983c5c11d18ef2e41e379a..5bf408d86f1a31067844850fdadf6307bedc2b70 100644 (file)
@@ -70,8 +70,8 @@ int dbox_storage_create(struct mail_storage *storage,
 void dbox_storage_destroy(struct mail_storage *storage);
 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);
-int dbox_mailbox_open(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);
 int dbox_mailbox_create(struct mailbox *box,
                        const struct mailbox_update *update, bool directory);
 int dbox_mailbox_create_indexes(struct mailbox *box,
index 74718ef2cac83d68d35abbae54ed55f37d075092..7260c744c20e9d9cf44f2feefc779138a7b70f7f 100644 (file)
@@ -170,10 +170,11 @@ mdbox_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
 int mdbox_mailbox_open(struct mailbox *box)
 {
        struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)box;
+       time_t path_ctime;
 
-       if (dbox_mailbox_check_existence(box) < 0)
+       if (dbox_mailbox_check_existence(box, &path_ctime) < 0)
                return -1;
-       if (dbox_mailbox_open(box) < 0)
+       if (dbox_mailbox_open(box, path_ctime) < 0)
                return -1;
 
        mbox->ext_id =
index 049c9345daf897e80f63fcf84ac1a00a34b7717b..0d92d3f288f7c87c28369479631f5a60b12c69b5 100644 (file)
@@ -332,14 +332,15 @@ static int sdbox_mailbox_open(struct mailbox *box)
        struct sdbox_mailbox *mbox = (struct sdbox_mailbox *)box;
        struct sdbox_index_header hdr;
        bool need_resize;
+       time_t path_ctime;
 
-       if (dbox_mailbox_check_existence(box) < 0)
+       if (dbox_mailbox_check_existence(box, &path_ctime) < 0)
                return -1;
 
        if (sdbox_mailbox_alloc_index(mbox) < 0)
                return -1;
 
-       if (dbox_mailbox_open(box) < 0)
+       if (dbox_mailbox_open(box, path_ctime) < 0)
                return -1;
 
        if (box->creating) {