Skip to content

Commit

Permalink
fs-posix: Added "dirs" parameter to enable explicit directory removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Jun 21, 2016
1 parent aed5d5c commit 9826e14
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/lib-fs/fs-posix.c
Expand Up @@ -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 {
Expand Down Expand Up @@ -100,6 +101,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) {
Expand Down Expand Up @@ -129,13 +132,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
Expand Down Expand Up @@ -197,6 +208,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;

Expand Down

0 comments on commit 9826e14

Please sign in to comment.