dovecot-2.0: mdbox: Automatically delete old temp.* files from s...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Apr 26 17:56:43 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/abf262317b2c
changeset: 11192:abf262317b2c
user: Timo Sirainen <tss at iki.fi>
date: Mon Apr 26 17:56:41 2010 +0300
description:
mdbox: Automatically delete old temp.* files from storage/ directory.
diffstat:
src/lib-storage/index/dbox-common/dbox-file.c | 2 +-
src/lib-storage/index/dbox-common/dbox-storage.h | 1 +
src/lib-storage/index/dbox-multi/mdbox-map.c | 20 ++++++++++++++++++++
3 files changed, 22 insertions(+), 1 deletions(-)
diffs (67 lines):
diff -r 4f6fa828d0c9 -r abf262317b2c src/lib-storage/index/dbox-common/dbox-file.c
--- 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,
diff -r 4f6fa828d0c9 -r abf262317b2c src/lib-storage/index/dbox-common/dbox-storage.h
--- 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"
diff -r 4f6fa828d0c9 -r abf262317b2c src/lib-storage/index/dbox-multi/mdbox-map.c
--- 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;
}
More information about the dovecot-cvs
mailing list