]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: fs-posix - FS_METADATA_WRITE_FNAME replaces the full path
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 26 Apr 2018 15:14:27 +0000 (18:14 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 30 Apr 2018 13:03:51 +0000 (16:03 +0300)
This is how all the other fs drivers work, although the macro name is a bit
confusing.

src/lib-fs/fs-posix.c
src/lib-fs/test-fs-posix.c

index 0d416d77af8ea18e2737146d49871da732332552..5e89414710c54d250b7e111c6ffe203e4ac8b799 100644 (file)
@@ -448,19 +448,14 @@ fs_posix_read_stream(struct fs_file *_file, size_t max_buffer_size)
 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, *new_prefix, *p;
+       const char *new_fname;
 
        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_strconcat(new_prefix, new_fname, NULL);
+       file->file.path = i_strdup(new_fname);
 
        i_free(file->full_path);
        file->full_path = fs->path_prefix == NULL ? i_strdup(file->file.path) :
index 6ca6f90c996591eab671b9c435bcd30466482c8e..ada5a239a4080d96f4cb2cf2d9bbf2d0bcb84a52 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "str.h"
+#include "ostream.h"
 #include "fs-api.h"
 #include "safe-mkdir.h"
 #include "safe-mkstemp.h"
@@ -95,6 +96,20 @@ static void test_fs_posix(void)
        fs_file_deinit(&file);
        test_end();
 
+       test_begin("test-fs-posix file write fname rename");
+       file = fs_file_init(fs, "subdir/badfname", FS_OPEN_MODE_REPLACE);
+       struct ostream *output = fs_write_stream(file);
+       o_stream_nsend_str(output, "hello");
+       fs_set_metadata(file, FS_METADATA_WRITE_FNAME, "subdir/rename1");
+       test_assert(fs_write_stream_finish(file, &output) == 1);
+       test_assert(strcmp(fs_file_path(file), "subdir/rename1") == 0);
+       fs_file_deinit(&file);
+       file = fs_file_init(fs, "subdir/rename1", FS_OPEN_MODE_READONLY);
+       test_assert(fs_stat(file, &st) == 0);
+       test_assert(st.st_size == 5);
+       fs_file_deinit(&file);
+       test_end();
+
        fs_deinit(&fs);
 
 error_no_fs: