]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Code cleanup - expand LOG_WANT_ROTATE() macro
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 27 Mar 2017 14:44:45 +0000 (17:44 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 30 Mar 2017 18:04:53 +0000 (21:04 +0300)
There was no reason it had to be a macro. Also this fixes off-by-one
error when checking for log_rotate_min_size.

src/lib-index/mail-transaction-log.c

index 39af0a6fbc6a58c2206348eb17e66c4e0b42d4c7..61668c85109bf4d1bf1376bf856fe11496f71a77 100644 (file)
@@ -214,15 +214,21 @@ void mail_transaction_logs_clean(struct mail_transaction_log *log)
        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)