changeset 5881:7b7ce27f2b13 HEAD

Delete over 30 minutes old .log.2 files when opening indexes.
author Timo Sirainen <tss@iki.fi>
date Tue, 03 Jul 2007 04:22:40 +0300
parents 3f3c12bfdba6
children 40ce533c88f9
files src/lib-index/mail-transaction-log-private.h src/lib-index/mail-transaction-log.c
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
@@ -10,6 +10,9 @@
 #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)
 
 struct mail_transaction_log_file {
--- 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 @@
 	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 @@
 		log->open_file = file;
 		return ret;
 	}
-
 	mail_transaction_log_set_head(log, file);
+	mail_transaction_log_2_unlink_old(log);
 	return 1;
 }