dovecot: Delete over 30 minutes old .log.2 files when opening in...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jul 3 04:22:46 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/7b7ce27f2b13
changeset: 5881:7b7ce27f2b13
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jul 03 04:22:40 2007 +0300
description:
Delete over 30 minutes old .log.2 files when opening indexes.

diffstat:

2 files changed, 27 insertions(+), 1 deletion(-)
src/lib-index/mail-transaction-log-private.h |    3 +++
src/lib-index/mail-transaction-log.c         |   25 ++++++++++++++++++++++++-

diffs (56 lines):

diff -r 3f3c12bfdba6 -r 7b7ce27f2b13 src/lib-index/mail-transaction-log-private.h
--- a/src/lib-index/mail-transaction-log-private.h	Tue Jul 03 04:11:41 2007 +0300
+++ b/src/lib-index/mail-transaction-log-private.h	Tue Jul 03 04:22:40 2007 +0300
@@ -9,6 +9,9 @@
 /* If log is larger than MAX_SIZE, rotate regardless of the time */
 #define MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE (1024*1024)
 #define MAIL_TRANSACTION_LOG_ROTATE_TIME (60*5)
+
+/* Delete .log.2 files older than this many seconds */
+#define MAIL_TRANSACTION_LOG2_STALE_SECS (60*30)
 
 #define MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ((file)->fd == -1)
 
diff -r 3f3c12bfdba6 -r 7b7ce27f2b13 src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c	Tue Jul 03 04:11:41 2007 +0300
+++ b/src/lib-index/mail-transaction-log.c	Tue Jul 03 04:22:40 2007 +0300
@@ -49,6 +49,29 @@ mail_transaction_log_alloc(struct mail_i
 	return log;
 }
 
+static void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
+{
+	struct stat st;
+	const char *path;
+
+	path = t_strconcat(log->index->filepath,
+			   MAIL_TRANSACTION_LOG_SUFFIX".2", NULL);
+	if (stat(path, &st) < 0) {
+		if (errno != ENOENT && errno != ESTALE) {
+			mail_index_set_error(log->index,
+				"stat(%s) failed: %m", path);
+		}
+		return;
+	}
+
+	if (st.st_mtime + MAIL_TRANSACTION_LOG2_STALE_SECS <= ioloop_time) {
+		if (unlink(path) < 0 && errno != ENOENT) {
+			mail_index_set_error(log->index,
+				"unlink(%s) failed: %m", path);
+		}
+	}
+}
+
 int mail_transaction_log_open(struct mail_transaction_log *log)
 {
 	struct mail_transaction_log_file *file;
@@ -70,8 +93,8 @@ int mail_transaction_log_open(struct mai
 		log->open_file = file;
 		return ret;
 	}
-
 	mail_transaction_log_set_head(log, file);
+	mail_transaction_log_2_unlink_old(log);
 	return 1;
 }
 


More information about the dovecot-cvs mailing list