bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenfs_test_init(struct fs *_fs ATTR_UNUSED, const char *args ATTR_UNUSED,
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic enum fs_properties fs_test_get_properties(struct fs *_fs)
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainenstatic struct fs_file *fs_test_file_alloc(void)
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen struct test_fs_file *file = i_new(struct test_fs_file, 1);
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainenfs_test_file_init(struct fs_file *_file, const char *path,
b162e16ade1e0d9bfae62e366caf57a3132f5963Timo Sirainen enum fs_open_mode mode, enum fs_open_flags flags)
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen file->contents = buffer_create_dynamic(default_pool, 1024);
b162e16ade1e0d9bfae62e366caf57a3132f5963Timo Sirainen file->wait_async = (flags & FS_OPEN_FLAG_ASYNC) != 0;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic void fs_test_file_deinit(struct fs_file *_file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic void fs_test_file_close(struct fs_file *_file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic const char *fs_test_file_get_path(struct fs_file *_file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenfs_test_set_async_callback(struct fs_file *_file,
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
d34b8a75f3b74e26adc85b6436d033b1dcfaf9daTimo Sirainenstatic void fs_test_wait_async(struct fs *_fs ATTR_UNUSED)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenfs_test_set_metadata(struct fs_file *_file, const char *key,
b162e16ade1e0d9bfae62e366caf57a3132f5963Timo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic bool fs_test_prefetch(struct fs_file *_file ATTR_UNUSED,
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic void fs_test_stream_destroyed(struct test_fs_file *file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic struct istream *
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenfs_test_read_stream(struct fs_file *_file, size_t max_buffer_size ATTR_UNUSED)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen input = test_istream_create_data(file->contents->data,
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen i_stream_add_destroy_callback(input, fs_test_stream_destroyed, file);
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic void fs_test_write_stream(struct fs_file *_file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen _file->output = o_stream_create_buffer(file->contents);
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_write_stream_finish(struct fs_file *_file, bool success)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenfs_test_lock(struct fs_file *_file, unsigned int secs ATTR_UNUSED,
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic void fs_test_unlock(struct fs_lock *lock)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)lock->file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_exists(struct fs_file *_file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_stat(struct fs_file *_file, struct stat *st_r)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_copy(struct fs_file *_src, struct fs_file *_dest)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *dest = (struct test_fs_file *)_dest;
b162e16ade1e0d9bfae62e366caf57a3132f5963Timo Sirainen dest->copy_src = test_fs_file_get(_src->fs, fs_file_path(_src));
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen buffer_append_buf(dest->contents, src->contents, 0, (size_t)-1);
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_rename(struct fs_file *_src, struct fs_file *_dest)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *src = (struct test_fs_file *)_src;
b162e16ade1e0d9bfae62e366caf57a3132f5963Timo Sirainen struct test_fs_file *dest = (struct test_fs_file *)_dest;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_delete(struct fs_file *_file)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_file *file = (struct test_fs_file *)_file;
4d71d712b42285afbd2a997f3408142ef0d5f899Timo Sirainenstatic struct fs_iter *fs_test_iter_alloc(void)
4d71d712b42285afbd2a997f3408142ef0d5f899Timo Sirainen struct test_fs_iter *iter = i_new(struct test_fs_iter, 1);
4d71d712b42285afbd2a997f3408142ef0d5f899Timo Sirainenfs_test_iter_init(struct fs_iter *_iter, const char *path,
4d71d712b42285afbd2a997f3408142ef0d5f899Timo Sirainen struct test_fs_iter *iter = (struct test_fs_iter *)_iter;
4d71d712b42285afbd2a997f3408142ef0d5f899Timo Sirainen struct test_fs *fs = (struct test_fs *)_iter->fs;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic const char *fs_test_iter_next(struct fs_iter *_iter)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_iter *iter = (struct test_fs_iter *)_iter;
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs *fs = (struct test_fs *)_iter->fs;
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen size_t len, prev_dir_len = strlen(iter->prev_dir);
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen if (strncmp(fname, iter->prefix, iter->prefix_len) != 0)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen if ((_iter->flags & FS_ITER_FLAG_DIRS) == 0) {
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen continue; /* dir/ */
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainenstatic int fs_test_iter_deinit(struct fs_iter *_iter)
140afad728d78c56fb4c0256f94eb81a213688dbTimo Sirainen struct test_fs_iter *iter = (struct test_fs_iter *)_iter;
b162e16ade1e0d9bfae62e366caf57a3132f5963Timo Sirainenstruct test_fs_file *test_fs_file_get(struct fs *fs, const char *path)