changeset 18881:7f7b77feb9ce

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.
author Timo Sirainen <tss@iki.fi>
date Wed, 17 Jun 2015 16:37:37 +0300
parents d609454bdf64
children eddc7a17dd46
files src/lib-fs/fs-posix.c
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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: