changeset 443:e730a1dcaaff HEAD

Delete unused temp files.
author Timo Sirainen <tss@iki.fi>
date Wed, 16 Oct 2002 18:15:13 +0300
parents 2a25bf21557b
children 85ab93a7693b
files src/lib-index/mail-index-open.c src/lib-index/mail-index.h
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-open.c	Wed Oct 16 18:05:05 2002 +0300
+++ b/src/lib-index/mail-index-open.c	Wed Oct 16 18:15:13 2002 +0300
@@ -6,6 +6,7 @@
 #include "file-set-size.h"
 #include "hostpid.h"
 #include "mmap-util.h"
+#include "unlink-lockfiles.h"
 #include "write-full.h"
 #include "mail-index.h"
 #include "mail-index-data.h"
@@ -477,6 +478,12 @@
 	hdr->next_uid = 1;
 }
 
+static void mail_index_cleanup_temp_files(const char *dir)
+{
+	unlink_lockfiles(dir, t_strconcat("temp.", my_hostname, NULL),
+			 "temp.", time(NULL) - TEMP_FILE_TIMEOUT);
+}
+
 int mail_index_open(MailIndex *index, int update_recent, int fast)
 {
 	const char *name, *path;
@@ -486,6 +493,8 @@
 	/* this isn't initialized anywhere else */
 	index->fd = -1;
 
+	mail_index_cleanup_temp_files(index->dir);
+
 	name = mail_find_index(index);
 	if (name == NULL)
 		return FALSE;
@@ -504,6 +513,8 @@
 
 	i_assert(!index->opened);
 
+	mail_index_cleanup_temp_files(index->dir);
+
 	if (mail_index_open(index, update_recent, fast))
 		return TRUE;
 
--- a/src/lib-index/mail-index.h	Wed Oct 16 18:05:05 2002 +0300
+++ b/src/lib-index/mail-index.h	Wed Oct 16 18:15:13 2002 +0300
@@ -402,6 +402,10 @@
 /* Max. mmap()ed size for a message */
 #define MAIL_MMAP_BLOCK_SIZE (1024*256)
 
+/* Delete unused non-local temp files after 24h. Just to be sure we don't
+   delete it too early. The temp files don't harm much anyway. */
+#define TEMP_FILE_TIMEOUT (60*24)
+
 /* number of records to always keep allocated in index file,
    either used or unused */
 #define INDEX_MIN_RECORDS_COUNT 64