]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fs-posix: Strip trailing "/" from filenames
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 15 May 2018 14:50:27 +0000 (17:50 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 18 May 2018 07:02:56 +0000 (10:02 +0300)
This is mainly because "doveadm fs delete -R" adds it to indicate to the
fs-driver that the whole directory is wanted to be deleted. This change
fixes fs-posix to work with NFS, where otherwise unlink("symlink-to-dir/")
fails with ENOTDIR. Without NFS the same call succeeds.

src/lib-fs/fs-posix.c

index 08e733dd1c0f01ea2e03466aa0330c06a134d836..809547ae80342c35ab5dee136a03626d89d14a3b 100644 (file)
@@ -322,6 +322,13 @@ fs_posix_file_init(struct fs_file *_file, const char *path,
        struct posix_fs_file *file = (struct posix_fs_file *)_file;
        struct posix_fs *fs = (struct posix_fs *)_file->fs;
        guid_128_t guid;
+       size_t path_len = strlen(path);
+
+       if (path_len > 0 && path[path_len-1] == '/') {
+               /* deleting "path/" (used e.g. by doveadm fs delete) - strip
+                  out the trailing "/" since it doesn't work well with NFS. */
+               path = t_strndup(path, path_len-1);
+       }
 
        if (mode != FS_OPEN_MODE_CREATE_UNIQUE_128)
                file->file.path = i_strdup(path);