changeset 22939:828152a256d6

lib-fs: fs-metawrap - Pass FS_METADATA_WRITE_FNAME through to parent fs fs-metawrap in the middle pervented the renaming from working.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 26 Apr 2018 18:14:46 +0300
parents 6c815956e1de
children c7d47a5c5550
files src/lib-fs/fs-metawrap.c src/lib-fs/fs-test.c src/lib-fs/test-fs-metawrap.c
diffstat 3 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-fs/fs-metawrap.c	Thu Apr 26 16:42:40 2018 +0300
+++ b/src/lib-fs/fs-metawrap.c	Thu Apr 26 18:14:46 2018 +0300
@@ -157,7 +157,8 @@
 {
 	struct metawrap_fs_file *file = (struct metawrap_fs_file *)_file;
 
-	if (!file->fs->wrap_metadata)
+	if (!file->fs->wrap_metadata ||
+	    strcmp(key, FS_METADATA_WRITE_FNAME) == 0)
 		fs_set_metadata(_file->parent, key, value);
 	else {
 		fs_default_set_metadata(_file, key, value);
--- a/src/lib-fs/fs-test.c	Thu Apr 26 16:42:40 2018 +0300
+++ b/src/lib-fs/fs-test.c	Thu Apr 26 18:14:46 2018 +0300
@@ -97,7 +97,12 @@
 fs_test_set_metadata(struct fs_file *_file, const char *key,
 		     const char *value)
 {
-	fs_default_set_metadata(_file, key, value);
+	if (strcmp(key, FS_METADATA_WRITE_FNAME) == 0) {
+		i_free(_file->path);
+		_file->path = i_strdup(value);
+	} else {
+		fs_default_set_metadata(_file, key, value);
+	}
 }
 
 static int
--- a/src/lib-fs/test-fs-metawrap.c	Thu Apr 26 16:42:40 2018 +0300
+++ b/src/lib-fs/test-fs-metawrap.c	Thu Apr 26 18:14:46 2018 +0300
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "str.h"
 #include "istream.h"
+#include "ostream.h"
 #include "fs-test.h"
 #include "test-common.h"
 
@@ -69,12 +70,32 @@
 	test_end();
 }
 
+static void test_fs_metawrap_write_fname_rename(void)
+{
+	struct fs *fs;
+	const char *error;
+
+	test_begin("fs metawrap write fname rename");
+	if (fs_init("metawrap", "test", &fs_set, &fs, &error) < 0)
+		i_fatal("fs_init() failed: %s", error);
+	struct fs_file *file = fs_file_init(fs, "foo", FS_OPEN_MODE_REPLACE);
+	struct ostream *output = fs_write_stream(file);
+	o_stream_nsend_str(output, "test");
+	fs_set_metadata(file, FS_METADATA_WRITE_FNAME, "renamed");
+	test_assert(fs_write_stream_finish(file, &output) > 0);
+	test_assert(strcmp(fs_file_path(file), "renamed") == 0);
+	fs_file_deinit(&file);
+	fs_deinit(&fs);
+	test_end();
+}
+
 int main(void)
 {
 	static void (*test_functions[])(void) = {
 		test_fs_metawrap_stat,
 		test_fs_metawrap_async,
 		test_fs_metawrap_write_empty,
+		test_fs_metawrap_write_fname_rename,
 		NULL
 	};
 	return test_run(test_functions);