]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fs-posix: Hide temporary files from fs_iter_*()
authorTimo Sirainen <tss@iki.fi>
Wed, 17 Jun 2015 13:37:37 +0000 (16:37 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 17 Jun 2015 13:37:37 +0000 (16:37 +0300)
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.

src/lib-fs/fs-posix.c

index d8b39ee8910ffa01752416f6ad47729046c76eb0..7a50abe191f12203594bb6d9e93e4a210624a48d 100644 (file)
@@ -32,6 +32,7 @@ enum fs_posix_lock_method {
 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_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
 
        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 bool fs_posix_iter_want(struct posix_fs_iter *iter, const char *fname)
 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 @@ static const char *fs_posix_iter_next(struct fs_iter *_iter)
                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: