Skip to content

Commit

Permalink
lib-fs: fs-metawrap - Pass FS_METADATA_WRITE_FNAME through to parent fs
Browse files Browse the repository at this point in the history
fs-metawrap in the middle pervented the renaming from working.
  • Loading branch information
sirainen committed Apr 30, 2018
1 parent 7492886 commit ee71a81
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib-fs/fs-metawrap.c
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/lib-fs/fs-test.c
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/lib-fs/test-fs-metawrap.c
Expand Up @@ -3,6 +3,7 @@
#include "lib.h"
#include "str.h"
#include "istream.h"
#include "ostream.h"
#include "fs-test.h"
#include "test-common.h"

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ee71a81

Please sign in to comment.