# HG changeset patch # User Timo Sirainen # Date 1183425760 -10800 # Node ID 7b7ce27f2b13b054dad2d92858a2c71c5086cf24 # Parent 3f3c12bfdba6839b69243db93ccff6856c090e21 Delete over 30 minutes old .log.2 files when opening indexes. 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 @@ -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 { 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 @@ 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; }