]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fs-posix: Added "dirs" parameter to enable explicit directory removal.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Jun 2016 14:24:11 +0000 (17:24 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Jun 2016 14:24:47 +0000 (17:24 +0300)
src/lib-fs/fs-posix.c

index 3090f0d3405b83c0ba6e9994b3f4ff545195a5a6..646997504a10d8a2ff29633fc7ee1d5ba6343e42 100644 (file)
@@ -35,6 +35,7 @@ struct posix_fs {
        enum fs_posix_lock_method lock_method;
        mode_t mode;
        bool mode_auto;
+       bool have_dirs;
 };
 
 struct posix_fs_file {
@@ -104,6 +105,8 @@ fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
                                fs->path_prefix = i_strdup(arg + 7);
                } else if (strcmp(arg, "mode=auto") == 0) {
                        fs->mode_auto = TRUE;
+               } else if (strcmp(arg, "dirs") == 0) {
+                       fs->have_dirs = TRUE;
                } else if (strncmp(arg, "mode=", 5) == 0) {
                        unsigned int mode;
                        if (str_to_uint_oct(arg+5, &mode) < 0) {
@@ -133,13 +136,21 @@ static void fs_posix_deinit(struct fs *_fs)
        i_free(fs);
 }
 
-static enum fs_properties fs_posix_get_properties(struct fs *fs ATTR_UNUSED)
+static enum fs_properties fs_posix_get_properties(struct fs *_fs)
 {
-       /* FS_PROPERTY_DIRECTORIES not returned because fs_delete()
-          automatically rmdir()s parents. This could be changed later though,
-          but SIS code at least would need to be changed to support it. */
-       return FS_PROPERTY_LOCKS | FS_PROPERTY_FASTCOPY | FS_PROPERTY_RENAME |
+       struct posix_fs *fs = (struct posix_fs *)_fs;
+       enum fs_properties props =
+               FS_PROPERTY_LOCKS | FS_PROPERTY_FASTCOPY | FS_PROPERTY_RENAME |
                FS_PROPERTY_STAT | FS_PROPERTY_ITER | FS_PROPERTY_RELIABLEITER;
+
+       /* FS_PROPERTY_DIRECTORIES is not returned normally because fs_delete()
+          automatically rmdir()s parents. For backwards compatibility
+          (especially with SIS code) we'll do it that way, but optionally with
+          "dirs" parameter enable them. This is especially important to be
+          able to use doveadm fs commands to delete empty directories. */
+       if (fs->have_dirs)
+               props |= FS_PROPERTY_DIRECTORIES;
+       return props;
 }
 
 static int
@@ -201,6 +212,8 @@ static int fs_posix_rmdir_parents(struct posix_fs *fs, const char *path)
 {
        const char *p;
 
+       if (fs->have_dirs)
+               return 0;
        if (fs->root_path == NULL && fs->path_prefix == NULL)
                return 0;