From: Timo Sirainen Date: Mon, 26 Apr 2010 14:56:41 +0000 (+0300) Subject: mdbox: Automatically delete old temp.* files from storage/ directory. X-Git-Tag: 2.0.beta5~82 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b004d46b9bfe4144761fa5c3f3a4cd4a4b8c957f;p=thirdparty%2Fdovecot%2Fcore.git mdbox: Automatically delete old temp.* files from storage/ directory. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index 661653ab96..047df7c347 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -36,7 +36,7 @@ const char *dbox_generate_tmp_filename(void) { static unsigned int create_count = 0; - return t_strdup_printf("temp.%lu.P%sQ%uM%u.%s", + return t_strdup_printf(DBOX_TEMP_FILE_PREFIX"%lu.P%sQ%uM%u.%s", (unsigned long)ioloop_timeval.tv_sec, my_pid, create_count++, (unsigned int)ioloop_timeval.tv_usec, diff --git a/src/lib-storage/index/dbox-common/dbox-storage.h b/src/lib-storage/index/dbox-common/dbox-storage.h index 5c0a04001f..ea59d938ce 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.h +++ b/src/lib-storage/index/dbox-common/dbox-storage.h @@ -9,6 +9,7 @@ struct dbox_mail; #define DBOX_SUBSCRIPTION_FILE_NAME "subscriptions" #define DBOX_UIDVALIDITY_FILE_NAME "dovecot-uidvalidity" #define DBOX_INDEX_PREFIX "dovecot.index" +#define DBOX_TEMP_FILE_PREFIX "temp." #define DBOX_MAILBOX_DIR_NAME "mailboxes" #define DBOX_TRASH_DIR_NAME "trash" diff --git a/src/lib-storage/index/dbox-multi/mdbox-map.c b/src/lib-storage/index/dbox-multi/mdbox-map.c index 803cf1a062..1d827588ec 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -5,6 +5,7 @@ #include "hash.h" #include "ostream.h" #include "mkdir-parents.h" +#include "unlink-old-files.h" #include "mdbox-storage.h" #include "mdbox-file.h" #include "mdbox-map-private.h" @@ -99,6 +100,24 @@ static int dbox_map_mkdir_storage(struct dbox_map *map) return 0; } +static void dbox_map_cleanup(struct dbox_map *map) +{ + struct stat st; + + if (stat(map->path, &st) < 0) + return; + + /* check once in a while if there are temp files to clean up */ + if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) { + /* there haven't been any changes to this directory since we + last checked it. */ + } else if (st.st_atime < ioloop_time - DBOX_TMP_SCAN_SECS) { + /* time to scan */ + (void)unlink_old_files(map->path, DBOX_TEMP_FILE_PREFIX, + ioloop_time - DBOX_TMP_DELETE_SECS); + } +} + static int dbox_map_open_internal(struct dbox_map *map, bool create_missing) { enum mail_index_open_flags open_flags; @@ -130,6 +149,7 @@ static int dbox_map_open_internal(struct dbox_map *map, bool create_missing) } map->view = mail_index_view_open(map->index); + dbox_map_cleanup(map); return 1; }