From: Timo Sirainen Date: Tue, 21 Jun 2016 14:24:11 +0000 (+0300) Subject: fs-posix: Added "dirs" parameter to enable explicit directory removal. X-Git-Tag: 2.2.25.rc1~81 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c39000f9aa595e4fc15825f7045fb073d79ece2d;p=thirdparty%2Fdovecot%2Fcore.git fs-posix: Added "dirs" parameter to enable explicit directory removal. --- diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index 3090f0d340..646997504a 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -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;