[dovecot-cvs] dovecot/src/lib-index/maildir maildir-clean.c,NONE,1.1 Makefile.am,1.1.1.1,1.2 maildir-index.c,1.21,1.22 maildir-index.h,1.13,1.14

cras at procontrol.fi cras at procontrol.fi
Tue Feb 11 17:07:33 EET 2003


Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv30344/maildir

Modified Files:
	Makefile.am maildir-index.c maildir-index.h 
Added Files:
	maildir-clean.c 
Log Message:
Clean old files from Maildir tmp dirs.



--- NEW FILE: maildir-clean.c ---
/* Copyright (C) 2002 Timo Sirainen */

#include "lib.h"
#include "ioloop.h"
#include "maildir-index.h"

#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>

/* Clean files from tmp/ if they're older than 36 hours */
#define MAILDIR_CLEANUP_TIME (60 * 60 * 36)

void maildir_clean_tmp(const char *dir)
{
	time_t cleanup_time = ioloop_time - MAILDIR_CLEANUP_TIME;
	DIR *dirp;
	struct dirent *d;
	struct stat st;
	const char *path;

	dirp = opendir(dir);
	if (dirp == NULL) {
		i_error("opendir(%s) failed: %m", dir);
		return;
	}

	while ((d = readdir(dirp)) != NULL) {
		if (strcmp(d->d_name, ".") == 0 ||
		    strcmp(d->d_name, "..") == 0)
			continue;

		t_push();
		path = t_strconcat(dir, "/", d->d_name, NULL);
		if (stat(path, &st) < 0) {
			if (errno != ENOENT)
				i_error("stat(%s) failed: %m", path);
		} else if (st.st_mtime < cleanup_time &&
			   st.st_atime < cleanup_time &&
			   !S_ISDIR(st.st_mode)) {
			if (unlink(path) < 0 && errno != ENOENT)
				i_error("unlink(%s) failed: %m", path);
		}
		t_pop();
	}

	if (closedir(dirp) < 0)
		i_error("closedir(%s) failed: %m", dir);
}

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/Makefile.am,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Makefile.am	9 Aug 2002 09:16:13 -0000	1.1.1.1
+++ Makefile.am	11 Feb 2003 15:07:31 -0000	1.2
@@ -9,6 +9,7 @@
 libstorage_index_maildir_a_SOURCES = \
 	maildir-index.c \
 	maildir-build.c \
+	maildir-clean.c \
 	maildir-open.c \
 	maildir-rebuild.c \
 	maildir-sync.c \

Index: maildir-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- maildir-index.c	5 Jan 2003 13:09:52 -0000	1.21
+++ maildir-index.c	11 Feb 2003 15:07:31 -0000	1.22
@@ -11,6 +11,13 @@
 
 extern struct mail_index maildir_index;
 
+static int maildir_index_open(struct mail_index *index,
+			      int update_recent, int fast)
+{
+	maildir_clean_tmp(t_strconcat(index->mailbox_path, "/tmp", NULL));
+	return mail_index_open(index, update_recent, fast);
+}
+
 enum mail_flags maildir_filename_get_flags(const char *fname,
 					   enum mail_flags default_flags)
 {
@@ -236,7 +243,7 @@
 }
 
 struct mail_index maildir_index = {
-	mail_index_open,
+	maildir_index_open,
 	mail_index_open_or_create,
 	maildir_index_free,
 	mail_index_set_lock,

Index: maildir-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- maildir-index.h	5 Jan 2003 13:09:52 -0000	1.13
+++ maildir-index.h	11 Feb 2003 15:07:31 -0000	1.14
@@ -29,4 +29,6 @@
 int maildir_record_update(struct mail_index *index,
 			  struct mail_index_update *update, int fd);
 
+void maildir_clean_tmp(const char *dir);
+
 #endif




More information about the dovecot-cvs mailing list