changeset 22299:d8bb722cde68

dbox: Cleanup - reorganize old temp file cleanup code No functional changes. In preparation for the next commits.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 26 Jun 2017 18:59:17 +0300
parents c36d34f5d759
children 2c78da6b9590
files src/lib-storage/index/dbox-common/dbox-storage.c
diffstat 1 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Mon Jun 26 19:30:11 2017 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Mon Jun 26 18:59:17 2017 +0300
@@ -164,39 +164,39 @@
 	}
 }
 
-static bool
-dbox_cleanup_if_exists(struct mailbox_list *list, const char *path)
+static void
+dbox_cleanup_temp_files(struct mailbox_list *list, const char *path,
+			time_t last_scan_time, time_t last_change_time)
 {
-	struct stat st;
 	unsigned int interval = list->mail_set->mail_temp_scan_interval;
 
-	if (stat(path, &st) < 0)
-		return FALSE;
-
 	/* check once in a while if there are temp files to clean up */
 	if (interval == 0) {
 		/* disabled */
-	} else if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) {
-		/* there haven't been any changes to this directory since we
-		   last checked it. */
-	} else if (st.st_atime < ioloop_time - (time_t)interval) {
-		/* time to scan */
+	} else if (last_scan_time >= ioloop_time - (time_t)interval) {
+		/* not the time to scan it yet */
+	} 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;
+		}
 		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)
 {
 	const char *box_path = mailbox_get_path(box);
+	struct stat st;
 
-	if (dbox_cleanup_if_exists(box->list, box_path))
-		;
-	else if (errno == ENOENT || errno == ENAMETOOLONG) {
+	if (stat(box_path, &st) == 0) {
+		dbox_cleanup_temp_files(box->list, box_path,
+					st.st_atime, st.st_ctime);
+	} else if (errno == ENOENT || errno == ENAMETOOLONG) {
 		mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
 			T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname));
 		return -1;