dovecot: Scan dbox directories every 8 days and delete stale tem...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Dec 8 17:11:20 EET 2007
details: http://hg.dovecot.org/dovecot/rev/99ad673724ad
changeset: 6960:99ad673724ad
user: Timo Sirainen <tss at iki.fi>
date: Sat Dec 08 17:11:14 2007 +0200
description:
Scan dbox directories every 8 days and delete stale temp files.
diffstat:
2 files changed, 35 insertions(+), 2 deletions(-)
src/lib-storage/index/dbox/dbox-storage.c | 32 +++++++++++++++++++++++++++--
src/lib-storage/index/dbox/dbox-storage.h | 5 ++++
diffs (77 lines):
diff -r a1e271317eb2 -r 99ad673724ad src/lib-storage/index/dbox/dbox-storage.c
--- 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 @@ dbox_open(struct dbox_storage *storage,
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 @@ dbox_mailbox_open(struct mail_storage *_
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) {
diff -r a1e271317eb2 -r 99ad673724ad src/lib-storage/index/dbox/dbox-storage.h
--- 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
@@ -14,6 +14,11 @@
#define DBOX_MAIL_FILE_UID_PREFIX "u."
#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)
More information about the dovecot-cvs
mailing list