Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6960:99ad673724ad HEAD
Scan dbox directories every 8 days and delete stale temp files.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 08 Dec 2007 17:11:14 +0200 |
parents | a1e271317eb2 |
children | 16f761cdc910 |
files | src/lib-storage/index/dbox/dbox-storage.c src/lib-storage/index/dbox/dbox-storage.h |
diffstat | 2 files changed, 35 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/dbox/dbox-storage.c Sat Dec 08 17:10:42 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-storage.c Sat Dec 08 17:11:14 2007 +0200 @@ -6,6 +6,7 @@ #include "str.h" #include "mkdir-parents.h" #include "unlink-directory.h" +#include "unlink-old-files.h" #include "index-mail.h" #include "mail-copy.h" #include "dbox-sync.h" @@ -225,13 +226,40 @@ return &mbox->ibox.box; } +static bool +dbox_cleanup_if_exists(struct mail_storage *storage, const char *path) +{ + struct stat st; + + if (stat(path, &st) < 0) { + if (errno != ENOENT) { + mail_storage_set_critical(storage, + "stat(%s) failed: %m", path); + } + return FALSE; + } + + /* 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 */ + const char *prefix = + mailbox_list_get_global_temp_prefix(storage->list); + + (void)unlink_old_files(path, prefix, + ioloop_time - DBOX_TMP_DELETE_SECS); + } + return TRUE; +} + static struct mailbox * dbox_mailbox_open(struct mail_storage *_storage, const char *name, struct istream *input, enum mailbox_open_flags flags) { struct dbox_storage *storage = (struct dbox_storage *)_storage; const char *path; - struct stat st; if (input != NULL) { mail_storage_set_critical(_storage, @@ -241,7 +269,7 @@ path = mailbox_list_get_path(_storage->list, name, MAILBOX_LIST_PATH_TYPE_MAILBOX); - if (stat(path, &st) == 0) + if (dbox_cleanup_if_exists(_storage, path)) return dbox_open(storage, name, flags); else if (errno == ENOENT) { if (strcmp(name, "INBOX") == 0) {
--- a/src/lib-storage/index/dbox/dbox-storage.h Sat Dec 08 17:10:42 2007 +0200 +++ b/src/lib-storage/index/dbox/dbox-storage.h Sat Dec 08 17:11:14 2007 +0200 @@ -15,6 +15,11 @@ #define DBOX_MAIL_FILE_MULTI_FORMAT DBOX_MAIL_FILE_MULTI_PREFIX"%u" #define DBOX_MAIL_FILE_UID_FORMAT DBOX_MAIL_FILE_UID_PREFIX"%u" +/* How often to scan for stale temp files (based on dir's atime) */ +#define DBOX_TMP_SCAN_SECS (8*60*60) +/* Delete temp files having ctime older than this. */ +#define DBOX_TMP_DELETE_SECS (36*60*60) + /* Default rotation settings */ #define DBOX_DEFAULT_ROTATE_SIZE (2*1024*1024) #define DBOX_DEFAULT_ROTATE_MIN_SIZE (1024*16)