changeset 22301:d86a691543b4

dbox: Use mail_index_header.last_temp_file_scan instead of directory's atime This will be required for the following ITERINDEX change.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 28 Jun 2017 19:46:01 +0300
parents 2c78da6b9590
children 55d796ab90d8
files 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
diffstat 4 files changed, 26 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Wed Jun 28 19:41:21 2017 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Wed Jun 28 19:46:01 2017 +0300
@@ -164,7 +164,7 @@
 	}
 }
 
-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 @@
 	/* 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 @@
 					  "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;
 }
 
--- a/src/lib-storage/index/dbox-common/dbox-storage.h	Wed Jun 28 19:41:21 2017 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-storage.h	Wed Jun 28 19:46:01 2017 +0300
@@ -70,8 +70,8 @@
 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,
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Wed Jun 28 19:41:21 2017 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Wed Jun 28 19:46:01 2017 +0300
@@ -170,10 +170,11 @@
 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 =
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Wed Jun 28 19:41:21 2017 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Wed Jun 28 19:46:01 2017 +0300
@@ -332,14 +332,15 @@
 	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) {