changeset 21914:dbd455951158

fs-posix: Fix FS_METADATA_WRITE_FNAME to preserve the path It should only change the filename.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 07 Apr 2017 10:55:40 +0300
parents 4c81a48916cb
children 6ba293f64b49
files src/lib-fs/fs-posix.c
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-fs/fs-posix.c	Fri Apr 07 12:45:49 2017 +0300
+++ b/src/lib-fs/fs-posix.c	Fri Apr 07 10:55:40 2017 +0300
@@ -449,18 +449,23 @@
 static void fs_posix_write_rename_if_needed(struct posix_fs_file *file)
 {
 	struct posix_fs *fs = (struct posix_fs *)file->file.fs;
-	const char *new_fname;
+	const char *new_fname, *new_prefix, *p;
 
 	new_fname = fs_metadata_find(&file->file.metadata, FS_METADATA_WRITE_FNAME);
 	if (new_fname == NULL)
 		return;
 
+	p = strrchr(file->file.path, '/');
+	if (p == NULL)
+		new_prefix = "";
+	else
+		new_prefix = t_strdup_until(file->file.path, p+1);
 	i_free(file->file.path);
-	file->file.path = i_strdup(new_fname);
+	file->file.path = i_strconcat(new_prefix, new_fname, NULL);
 
 	i_free(file->full_path);
-	file->full_path = fs->path_prefix == NULL ? i_strdup(new_fname) :
-		i_strconcat(fs->path_prefix, new_fname, NULL);
+	file->full_path = fs->path_prefix == NULL ? i_strdup(file->file.path) :
+		i_strconcat(fs->path_prefix, file->file.path, NULL);
 }
 
 static int fs_posix_write_finish(struct posix_fs_file *file)