Beispiel #1
0
static void test_fs_async_copy(const char *test_name, struct fs *fs)
{
	struct fs_file *src, *dest;
	struct test_fs_file *test_file;

	test_begin(t_strdup_printf("%s: async copy", test_name));

	src = fs_file_init(fs, "foo", FS_OPEN_MODE_REPLACE);
	test_assert(fs_write(src, "source", 6) == 0);

	dest = fs_file_init(fs, "bar", FS_OPEN_MODE_REPLACE |
			    FS_OPEN_FLAG_ASYNC);

	test_assert(fs_copy(src, dest) == -1 && errno == EAGAIN);

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

	test_assert(fs_copy_finish_async(dest) == 0);
	test_assert(test_file->contents->used > 0);
	fs_file_deinit(&dest);

	fs_file_deinit(&src);
	test_end();
}
Beispiel #2
0
static void fs_compress_file_deinit(struct fs_file *_file)
{
	struct compress_fs_file *file = (struct compress_fs_file *)_file;

	if (file->super_read != _file->parent && file->super_read != NULL)
		fs_file_deinit(&file->super_read);
	fs_file_deinit(&_file->parent);
	i_free(file->file.path);
	i_free(file);
}
Beispiel #3
0
static void fs_sis_file_deinit(struct fs_file *_file)
{
	struct sis_fs_file *file = (struct sis_fs_file *)_file;

	fs_file_deinit(&file->hash_file);
	fs_file_deinit(&file->super);
	i_free(file->hash);
	i_free(file->hash_path);
	i_free(file->file.path);
	i_free(file);
}
Beispiel #4
0
static void fs_sis_queue_file_deinit(struct fs_file *_file)
{
	struct sis_queue_fs_file *file = (struct sis_queue_fs_file *)_file;

	if (file->super != NULL)
		fs_file_deinit(&file->super);
	i_free(file->file.path);
	i_free(file);
}
Beispiel #5
0
static void i_stream_fs_file_close(struct iostream_private *stream,
                                   bool close_parent ATTR_UNUSED)
{
    struct fs_file_istream *fstream = (struct fs_file_istream *)stream;

    if (fstream->istream.parent != NULL)
        i_stream_destroy(&fstream->istream.parent);
    fs_file_deinit(&fstream->file);
}
Beispiel #6
0
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();
}
Beispiel #7
0
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();
}
void fs_sis_try_unlink_hash_file(struct fs *sis_fs, struct fs_file *super_file)
{
	struct fs_file *hash_file;
	struct stat st1, st2;
	const char *dir, *hash, *hash_path;

	if (fs_sis_path_parse(sis_fs, super_file->path, &dir, &hash) == 0 &&
	    fs_stat(super_file, &st1) == 0 && st1.st_nlink == 2) {
		/* this may be the last link. if hashes/ file is the same,
		   delete it. */
		hash_path = t_strdup_printf("%s/"HASH_DIR_NAME"/%s", dir, hash);
		hash_file = fs_file_init(super_file->fs, hash_path,
					 FS_OPEN_MODE_READONLY);
		if (fs_stat(hash_file, &st2) == 0 &&
		    st1.st_ino == st2.st_ino &&
		    CMP_DEV_T(st1.st_dev, st2.st_dev)) {
			if (fs_delete(hash_file) < 0)
				i_error("%s", fs_last_error(hash_file->fs));
		}
		fs_file_deinit(&hash_file);
	}
}
Beispiel #9
0
static void test_fs_metawrap_stat(void)
{
	struct fs *fs;
	struct fs_file *file;
	struct test_fs_file *test_file;
	struct istream *input;
	struct stat st;
	const char *error;
	unsigned int i;

	test_begin("fs metawrap stat");

	if (fs_init("metawrap", "test", &fs_set, &fs, &error) < 0)
		i_fatal("fs_init() failed: %s", error);

	for (i = 0; i < 2; i++) {
		file = fs_file_init(fs, "foo", FS_OPEN_MODE_READONLY);

		test_file = test_fs_file_get(fs, "foo");
		str_append(test_file->contents, "key:value\n\n12345678901234567890");

		if (i == 0) {
			input = fs_read_stream(file, 2);
			test_istream_set_max_buffer_size(test_file->input, 2);
		} else {
			input = NULL;
		}

		test_assert_idx(fs_stat(file, &st) == 0 && st.st_size == 20, i);

		if (input != NULL)
			i_stream_unref(&input);
		fs_file_deinit(&file);
	}
	fs_deinit(&fs);
	test_end();
}