コード例 #1
0
ファイル: fs-sis.c プロジェクト: via/dovecot-clouddb
static int fs_sis_write_stream_finish(struct fs_file *_file, bool success)
{
	struct sis_fs_file *file = (struct sis_fs_file *)_file;

	if (!success) {
		fs_write_stream_abort(file->super, &file->fs_output);
		fs_sis_file_copy_error(file);
		return -1;
	}

	if (file->hash_input != NULL &&
	    o_stream_cmp_equals(_file->output) &&
	    i_stream_is_eof(file->hash_input)) {
		if (fs_sis_try_link(file)) {
			fs_write_stream_abort(file->super, &file->fs_output);
			return 0;
		}
	}

	if (fs_write_stream_finish(file->super, &file->fs_output) < 0) {
		fs_sis_file_copy_error(file);
		return -1;
	}
	T_BEGIN {
		fs_sis_replace_hash_file(file);
	} T_END;
	return 0;
}
コード例 #2
0
ファイル: fs-crypt-common.c プロジェクト: manuelm/dovecot
static int fs_crypt_write_stream_finish(struct fs_file *_file, bool success)
{
	struct crypt_fs_file *file = (struct crypt_fs_file *)_file;
	struct istream *input;
	int ret;

	if (_file->output != NULL) {
		if (_file->output == file->super_output)
			_file->output = NULL;
		else
			o_stream_unref(&_file->output);
	}
	if (!success) {
		if (file->super_output != NULL) {
			/* no encryption */
			i_assert(file->temp_output == NULL);
			fs_write_stream_abort_error(_file->parent, &file->super_output,
						    "write(%s) failed: %s",
						    o_stream_get_name(file->super_output),
						    o_stream_get_error(file->super_output));
		} else if (file->temp_output != NULL) {
			o_stream_destroy(&file->temp_output);
		}
		return -1;
	}

	if (file->super_output != NULL) {
		/* no encrypt */
		i_assert(file->temp_output == NULL);
		return fs_write_stream_finish(_file->parent, &file->super_output);
	}
	if (file->temp_output == NULL) {
		/* finishing up */
		i_assert(file->super_output == NULL);
		return fs_write_stream_finish_async(_file->parent);
	}

	/* finish writing the temporary file */
	input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE);
	file->super_output = fs_write_stream(_file->parent);
	o_stream_nsend_istream(file->super_output, input);
	ret = fs_write_stream_finish(_file->parent, &file->super_output);
	i_stream_unref(&input);
	return ret;
}
コード例 #3
0
ファイル: fs-compress.c プロジェクト: nikwrt/dovecot-core
static int fs_compress_write_stream_finish(struct fs_file *_file, bool success)
{
	struct compress_fs_file *file = (struct compress_fs_file *)_file;
	struct istream *input;
	int ret;

	if (_file->output != NULL) {
		if (_file->output->closed)
			success = FALSE;
		if (_file->output == file->super_output)
			_file->output = NULL;
		else
			o_stream_unref(&_file->output);
	}
	if (!success) {
		if (file->temp_output != NULL)
			o_stream_destroy(&file->temp_output);
		if (file->super_output != NULL)
			fs_write_stream_abort(_file->parent, &file->super_output);
		return -1;
	}

	if (file->super_output != NULL) {
		i_assert(file->temp_output == NULL);
		return fs_write_stream_finish(_file->parent, &file->super_output);
	}
	if (file->temp_output == NULL) {
		/* finishing up */
		i_assert(file->super_output == NULL);
		return fs_write_stream_finish(_file->parent, &file->temp_output);
	}
	/* finish writing the temporary file */
	input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE);
	file->super_output = fs_write_stream(_file->parent);
	o_stream_nsend_istream(file->super_output, input);
	ret = fs_write_stream_finish(_file->parent, &file->super_output);
	i_stream_unref(&input);
	return ret;
}
コード例 #4
0
ファイル: test-fs-metawrap.c プロジェクト: manuelm/dovecot
static void test_fs_metawrap_write_empty(void)
{
	struct fs *fs;
	const char *error;

	test_begin("fs metawrap write empty file");
	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);
	test_assert(fs_write_stream_finish(file, &output) > 0);
	fs_file_deinit(&file);
	fs_deinit(&fs);
	test_end();
}
コード例 #5
0
ファイル: fs-test-async.c プロジェクト: bdraco/core
static void test_fs_async_write(const char *test_name, struct fs *fs)
{
	struct fs_file *file;
	struct test_fs_file *test_file;
	struct ostream *output;
	unsigned int i;

	test_begin(t_strdup_printf("%s: async write", test_name));
	for (i = 0; i < 3; i++) {
		file = fs_file_init(fs, "foo", FS_OPEN_MODE_REPLACE |
				    FS_OPEN_FLAG_ASYNC);
		output = fs_write_stream(file);

		o_stream_nsend_str(output, "12345");
		if (i < 2) {
			test_assert(fs_write_stream_finish(file, &output) == 0);
			test_assert(output == NULL);
			test_assert(fs_write_stream_finish_async(file) == 0);
		}

		test_file = test_fs_file_get(fs, "foo");
		test_file->wait_async = FALSE;

		switch (i) {
		case 0:
			test_assert(fs_write_stream_finish_async(file) > 0);
			test_assert(test_file->contents->used > 0);
			break;
		case 1:
			test_file->io_failure = TRUE;
			test_assert(fs_write_stream_finish_async(file) < 0);
			test_assert(test_file->contents->used == 0);
			break;
		case 2:
			fs_write_stream_abort_error(file, &output, "test");
			test_assert(test_file->contents->used == 0);
			break;
		}
		fs_file_deinit(&file);
	}
	test_end();
}