Mercurial > dovecot > core-2.2
changeset 11192:abf262317b2c HEAD
mdbox: Automatically delete old temp.* files from storage/ directory.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 26 Apr 2010 17:56:41 +0300 |
parents | 4f6fa828d0c9 |
children | f0d13439baea |
files | src/lib-storage/index/dbox-common/dbox-file.c src/lib-storage/index/dbox-common/dbox-storage.h src/lib-storage/index/dbox-multi/mdbox-map.c |
diffstat | 3 files changed, 22 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-file.c Mon Apr 26 17:46:13 2010 +0300 +++ b/src/lib-storage/index/dbox-common/dbox-file.c Mon Apr 26 17:56:41 2010 +0300 @@ -36,7 +36,7 @@ { 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,
--- a/src/lib-storage/index/dbox-common/dbox-storage.h Mon Apr 26 17:46:13 2010 +0300 +++ b/src/lib-storage/index/dbox-common/dbox-storage.h Mon Apr 26 17:56:41 2010 +0300 @@ -9,6 +9,7 @@ #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"
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Apr 26 17:46:13 2010 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Apr 26 17:56:41 2010 +0300 @@ -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 @@ 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 @@ } map->view = mail_index_view_open(map->index); + dbox_map_cleanup(map); return 1; }