dovecot-2.2: fs-posix: Hide temporary files from fs_iter_*()

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 17 13:40:14 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/7f7b77feb9ce
changeset: 18881:7f7b77feb9ce
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 17 16:37:37 2015 +0300
description:
fs-posix: Hide temporary files from fs_iter_*()
Those could exist just because another process is just using them to create
new files to the directory. Although they could also be older files caused
by earlier crashes. It would probably be a good idea to have fs_iter_*()
delete the old temporary files automatically.

diffstat:

 src/lib-fs/fs-posix.c |  6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diffs (37 lines):

diff -r d609454bdf64 -r 7f7b77feb9ce src/lib-fs/fs-posix.c
--- a/src/lib-fs/fs-posix.c	Wed Jun 17 14:25:48 2015 +0300
+++ b/src/lib-fs/fs-posix.c	Wed Jun 17 16:37:37 2015 +0300
@@ -32,6 +32,7 @@
 struct posix_fs {
 	struct fs fs;
 	char *temp_file_prefix, *root_path, *path_prefix;
+	unsigned int temp_file_prefix_len;
 	enum fs_posix_lock_method lock_method;
 	mode_t mode, dir_mode;
 };
@@ -79,6 +80,7 @@
 
 	fs->temp_file_prefix = set->temp_file_prefix != NULL ?
 		i_strdup(set->temp_file_prefix) : i_strdup("temp.dovecot.");
+	fs->temp_file_prefix_len = strlen(fs->temp_file_prefix);
 	fs->root_path = i_strdup(set->root_path);
 	fs->fs.set.temp_file_prefix = fs->temp_file_prefix;
 	fs->fs.set.root_path = fs->root_path;
@@ -731,6 +733,7 @@
 static const char *fs_posix_iter_next(struct fs_iter *_iter)
 {
 	struct posix_fs_iter *iter = (struct posix_fs_iter *)_iter;
+	struct posix_fs *fs = (struct posix_fs *)_iter->fs;
 	struct dirent *d;
 
 	if (iter->dir == NULL)
@@ -741,6 +744,9 @@
 		if (strcmp(d->d_name, ".") == 0 ||
 		    strcmp(d->d_name, "..") == 0)
 			continue;
+		if (strncmp(d->d_name, fs->temp_file_prefix,
+			    fs->temp_file_prefix_len) == 0)
+			continue;
 #ifdef HAVE_DIRENT_D_TYPE
 		switch (d->d_type) {
 		case DT_UNKNOWN:


More information about the dovecot-cvs mailing list