bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainenfs_sis_queue_init(struct fs *_fs, const char *args,
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainen struct sis_queue_fs *fs = (struct sis_queue_fs *)_fs;
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainen const char *p, *parent_name, *parent_args, *error;
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen /* <queue_dir>:<parent fs>[:<args>] */
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainen fs_set_error(_fs, "Parent filesystem not given as parameter");
d4c3d55021bcbf2b062f4782b1cde9115d35aefcTimo Sirainen parent_name = t_strdup_until(parent_name, parent_args++);
e597ab14b6fc01a602b35d26177d09643af8fed5Timo Sirainen if (fs_init(parent_name, parent_args, set, &_fs->parent, &error) < 0) {
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainenstatic void fs_sis_queue_deinit(struct fs *_fs)
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen struct sis_queue_fs *fs = (struct sis_queue_fs *)_fs;
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainenstatic struct fs_file *fs_sis_queue_file_alloc(void)
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen struct sis_queue_fs_file *file = i_new(struct sis_queue_fs_file, 1);
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainenfs_sis_queue_file_init(struct fs_file *_file, const char *path,
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainen enum fs_open_mode mode, enum fs_open_flags flags)
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file;
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen struct sis_queue_fs *fs = (struct sis_queue_fs *)_file->fs;
86ad48a2e740bd63a9b7299d7f3e229831d9b303Timo Sirainen fs_set_error(_file->fs, "APPEND mode not supported");
6d1218e68ce883735ffde9d7907e626ab81b9fb5Timo Sirainen file->file.parent = fs_file_init_parent(_file, path, mode | flags);
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainenstatic void fs_sis_queue_file_deinit(struct fs_file *_file)
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file;
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainenstatic void fs_sis_queue_add(struct sis_queue_fs_file *file)
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen struct sis_queue_fs *fs = (struct sis_queue_fs *)file->file.fs;
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen queue_path = t_strdup_printf("%s/%s", fs->queue_dir, fname);
6d1218e68ce883735ffde9d7907e626ab81b9fb5Timo Sirainen queue_file = fs_file_init_parent(&file->file, queue_path, FS_OPEN_MODE_CREATE);
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen if (fs_write(queue_file, "", 0) < 0 && errno != EEXIST)
b254b8ec1ea03f400f1390ec24afd826a8c335d9Timo Sirainen e_error(file->file.event, "%s", fs_file_last_error(queue_file));
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainenstatic int fs_sis_queue_write(struct fs_file *_file, const void *data, size_t size)
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file;
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainenstatic void fs_sis_queue_write_stream(struct fs_file *_file)
6516e7c2cfb84bbdaff7d748df0a0f1f6f39f75dTimo Sirainen _file->output = o_stream_create_error_str(EINVAL, "%s",
8b3f557cda9023b87b183e364cb7f7c7b0906950Timo Sirainen _file->output = fs_write_stream(_file->parent);
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainen o_stream_set_name(_file->output, _file->path);
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainenstatic int fs_sis_queue_write_stream_finish(struct fs_file *_file, bool success)
c33d3f93abf8392fdc60e12bea41ffd12cc85a8dTimo Sirainen struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file;
b8f4e3aa58caa7ee16cf21a21f92521bf05cbdc4Aki Tuomi fs_write_stream_abort_parent(_file, &_file->output);
8b3f557cda9023b87b183e364cb7f7c7b0906950Timo Sirainen if (fs_write_stream_finish(_file->parent, &_file->output) < 0)
c59b9c273b41f7bcf51f6803110b67813879ff05Timo Sirainenstatic int fs_sis_queue_delete(struct fs_file *_file)