changeset 21853:99459f819e50

lib-index: Code cleanup - expand LOG_WANT_ROTATE() macro There was no reason it had to be a macro. Also this fixes off-by-one error when checking for log_rotate_min_size.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 27 Mar 2017 17:44:45 +0300
parents 4764b26594af
children 3ffd4442b22c
files src/lib-index/mail-transaction-log.c
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log.c	Fri Mar 17 10:28:36 2017 +0200
+++ b/src/lib-index/mail-transaction-log.c	Mon Mar 27 17:44:45 2017 +0300
@@ -214,15 +214,21 @@
 	i_assert(log->head == NULL || log->files != NULL);
 }
 
-#define LOG_WANT_ROTATE(file) \
-	(((file)->sync_offset > (file)->log->index->log_rotate_min_size && \
-	  (file)->hdr.create_stamp < \
-	   ioloop_time - (file)->log->index->log_rotate_min_created_ago_secs) || \
-	 ((file)->sync_offset > (file)->log->index->log_rotate_max_size))
-
 bool mail_transaction_log_want_rotate(struct mail_transaction_log *log)
 {
-	return LOG_WANT_ROTATE(log->head);
+	struct mail_transaction_log_file *file = log->head;
+
+	if (file->sync_offset > log->index->log_rotate_max_size) {
+		/* file is too large, definitely rotate */
+		return TRUE;
+	}
+	if (file->sync_offset < log->index->log_rotate_min_size) {
+		/* file is still too small */
+		return FALSE;
+	}
+	/* rotate if the timestamp is old enough */
+	return file->hdr.create_stamp <
+		ioloop_time - log->index->log_rotate_min_created_ago_secs;
 }
 
 int mail_transaction_log_rotate(struct mail_transaction_log *log, bool reset)