From: Timo Sirainen Date: Thu, 26 Apr 2018 15:14:46 +0000 (+0300) Subject: lib-fs: fs-metawrap - Pass FS_METADATA_WRITE_FNAME through to parent fs X-Git-Tag: 2.3.9~1911 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=534200e4bcfb5425ef317b4ca1262bbe9dd3ca0d;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: fs-metawrap - Pass FS_METADATA_WRITE_FNAME through to parent fs fs-metawrap in the middle pervented the renaming from working. --- diff --git a/src/lib-fs/fs-metawrap.c b/src/lib-fs/fs-metawrap.c index c6454b8914..73b69dadd0 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -158,7 +158,8 @@ fs_metawrap_set_metadata(struct fs_file *_file, const char *key, { 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); diff --git a/src/lib-fs/fs-test.c b/src/lib-fs/fs-test.c index a423839696..67528bddaa 100644 --- a/src/lib-fs/fs-test.c +++ b/src/lib-fs/fs-test.c @@ -99,7 +99,12 @@ static void 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 diff --git a/src/lib-fs/test-fs-metawrap.c b/src/lib-fs/test-fs-metawrap.c index da02eb92ee..cda0a2e8ad 100644 --- a/src/lib-fs/test-fs-metawrap.c +++ b/src/lib-fs/test-fs-metawrap.c @@ -3,6 +3,7 @@ #include "lib.h" #include "str.h" #include "istream.h" +#include "ostream.h" #include "fs-test.h" #include "test-common.h" @@ -68,12 +69,32 @@ static void test_fs_metawrap_write_empty(void) 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 (*const 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);