From: Timo Sirainen Date: Wed, 28 Jun 2017 16:46:01 +0000 (+0300) Subject: dbox: Use mail_index_header.last_temp_file_scan instead of directory's atime X-Git-Tag: 2.2.32.rc1~131 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c2f60b2c9b10ea4a8c452cdfb6e9c810d0bf6c9;p=thirdparty%2Fdovecot%2Fcore.git dbox: Use mail_index_header.last_temp_file_scan instead of directory's atime This will be required for the following ITERINDEX change. --- diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index add4522b7c..463fdb18e8 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -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; } diff --git a/src/lib-storage/index/dbox-common/dbox-storage.h b/src/lib-storage/index/dbox-common/dbox-storage.h index f6117a27b1..5bf408d86f 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.h +++ b/src/lib-storage/index/dbox-common/dbox-storage.h @@ -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, diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index 74718ef2ca..7260c744c2 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -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 = diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 049c9345da..0d92d3f288 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -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) {