From: Timo Sirainen Date: Tue, 15 May 2018 14:50:27 +0000 (+0300) Subject: fs-posix: Strip trailing "/" from filenames X-Git-Tag: 2.3.2.rc1~117 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b6c7cd53e9b840fd560da5957bbddbe1f2e9530c;p=thirdparty%2Fdovecot%2Fcore.git fs-posix: Strip trailing "/" from filenames 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. --- diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index 08e733dd1c..809547ae80 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -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);