]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Automatically delete old temp.* files from storage/ directory.
authorTimo Sirainen <tss@iki.fi>
Mon, 26 Apr 2010 14:56:41 +0000 (17:56 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 26 Apr 2010 14:56:41 +0000 (17:56 +0300)
--HG--
branch : HEAD

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

index 661653ab9685e57669aacc690605ac34d412b415..047df7c3472a38ee6d83f353d322082812197229 100644 (file)
@@ -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,
index 5c0a04001f794cdb145c267c2616671355f47182..ea59d938ce5158d67b64b8fbb8c75b2bfb693fe1 100644 (file)
@@ -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"
index 803cf1a062be25a89591245d5fb949868522f0e5..1d827588ec0771d46b95f6927b7c6bfdc21fbdd3 100644 (file)
@@ -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;
 }