Mercurial > dovecot > core-2.2
annotate src/lib-fs/fs-test.c @ 21390:2e2563132d5f
Updated copyright notices to include the year 2017.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Wed, 11 Jan 2017 02:51:13 +0100 |
parents | 59437f8764c6 |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21389
diff
changeset
|
1 /* Copyright (c) 2016-2017 Dovecot authors, see the included COPYING file */ |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
2 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
4 #include "istream.h" |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
5 #include "ostream.h" |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
6 #include "test-common.h" |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
7 #include "fs-test.h" |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
8 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
9 static struct fs *fs_test_alloc(void) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
10 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
11 struct test_fs *fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
12 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
13 fs = i_new(struct test_fs, 1); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
14 fs->fs = fs_class_test; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
15 i_array_init(&fs->iter_files, 32); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
16 return &fs->fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
17 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
18 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
19 static int |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
20 fs_test_init(struct fs *_fs ATTR_UNUSED, const char *args ATTR_UNUSED, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
21 const struct fs_settings *set ATTR_UNUSED) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
22 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
23 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
24 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
25 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
26 static void fs_test_deinit(struct fs *_fs) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
27 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
28 struct test_fs *fs = (struct test_fs *)_fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
29 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
30 array_free(&fs->iter_files); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
31 i_free(fs); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
32 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
33 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
34 static enum fs_properties fs_test_get_properties(struct fs *_fs) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
35 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
36 struct test_fs *fs = (struct test_fs *)_fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
37 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
38 return fs->properties; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
39 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
40 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
41 static struct fs_file * |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
42 fs_test_file_init(struct fs *_fs, const char *path, |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
43 enum fs_open_mode mode, enum fs_open_flags flags) |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
44 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
45 struct test_fs_file *file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
46 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
47 file = i_new(struct test_fs_file, 1); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
48 file->file.fs = _fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
49 file->file.path = i_strdup(path); |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
50 file->file.flags = flags; |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
51 file->mode = mode; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
52 file->contents = buffer_create_dynamic(default_pool, 1024); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
53 file->exists = TRUE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
54 file->seekable = TRUE; |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
55 file->wait_async = (flags & FS_OPEN_FLAG_ASYNC) != 0; |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
56 return &file->file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
57 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
58 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
59 static void fs_test_file_deinit(struct fs_file *_file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
60 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
61 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
62 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
63 buffer_free(&file->contents); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
64 i_free(file->file.path); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
65 i_free(file); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
66 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
67 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
68 static void fs_test_file_close(struct fs_file *_file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
69 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
70 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
71 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
72 file->closed = TRUE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
73 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
74 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
75 static const char *fs_test_file_get_path(struct fs_file *_file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
76 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
77 return _file->path; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
78 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
79 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
80 static void |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
81 fs_test_set_async_callback(struct fs_file *_file, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
82 fs_file_async_callback_t *callback, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
83 void *context) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
84 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
85 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
86 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
87 file->async_callback = callback; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
88 file->async_context = context; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
89 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
90 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
91 static int fs_test_wait_async(struct fs *_fs ATTR_UNUSED) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
92 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
93 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
94 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
95 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
96 static void |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
97 fs_test_set_metadata(struct fs_file *_file, const char *key, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
98 const char *value) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
99 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
100 fs_default_set_metadata(_file, key, value); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
101 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
102 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
103 static int |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
104 fs_test_get_metadata(struct fs_file *_file, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
105 const ARRAY_TYPE(fs_metadata) **metadata_r) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
106 { |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
107 struct test_fs_file *file = (struct test_fs_file *)_file; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
108 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
109 if (file->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
110 fs_set_error_async(_file->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
111 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
112 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
113 if (file->io_failure) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
114 errno = EIO; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
115 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
116 } |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
117 fs_metadata_init(_file); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
118 *metadata_r = &_file->metadata; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
119 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
120 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
121 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
122 static bool fs_test_prefetch(struct fs_file *_file ATTR_UNUSED, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
123 uoff_t length ATTR_UNUSED) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
124 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
125 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
126 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
127 file->prefetched = TRUE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
128 return TRUE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
129 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
130 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
131 static void fs_test_stream_destroyed(struct test_fs_file *file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
132 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
133 i_assert(file->input != NULL); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
134 file->input = NULL; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
135 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
136 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
137 static struct istream * |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
138 fs_test_read_stream(struct fs_file *_file, size_t max_buffer_size ATTR_UNUSED) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
139 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
140 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
141 struct istream *input; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
142 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
143 i_assert(file->input == NULL); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
144 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
145 if (!file->exists) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
146 return i_stream_create_error(ENOENT); |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
147 if (file->io_failure) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
148 return i_stream_create_error(EIO); |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
149 input = test_istream_create_data(file->contents->data, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
150 file->contents->used); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
151 i_stream_add_destroy_callback(input, fs_test_stream_destroyed, file); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
152 if (!file->seekable) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
153 input->seekable = FALSE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
154 file->input = input; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
155 return input; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
156 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
157 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
158 static void fs_test_write_stream(struct fs_file *_file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
159 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
160 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
161 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
162 i_assert(_file->output == NULL); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
163 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
164 buffer_set_used_size(file->contents, 0); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
165 _file->output = o_stream_create_buffer(file->contents); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
166 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
167 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
168 static int fs_test_write_stream_finish(struct fs_file *_file, bool success) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
169 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
170 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
171 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
172 if (_file->output != NULL) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
173 o_stream_destroy(&_file->output); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
174 if (file->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
175 fs_set_error_async(_file->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
176 return 0; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
177 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
178 if (file->io_failure) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
179 success = FALSE; |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
180 if (!success) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
181 buffer_set_used_size(file->contents, 0); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
182 return success ? 1 : -1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
183 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
184 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
185 static int |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
186 fs_test_lock(struct fs_file *_file, unsigned int secs ATTR_UNUSED, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
187 struct fs_lock **lock_r) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
188 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
189 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
190 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
191 if (file->locked) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
192 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
193 file->locked = TRUE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
194 *lock_r = i_new(struct fs_lock, 1); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
195 (*lock_r)->file = _file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
196 return 1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
197 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
198 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
199 static void fs_test_unlock(struct fs_lock *lock) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
200 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
201 struct test_fs_file *file = (struct test_fs_file *)lock->file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
202 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
203 file->locked = FALSE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
204 i_free(lock); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
205 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
206 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
207 static int fs_test_exists(struct fs_file *_file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
208 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
209 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
210 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
211 if (file->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
212 fs_set_error_async(_file->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
213 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
214 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
215 if (file->io_failure) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
216 errno = EIO; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
217 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
218 } |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
219 return file->exists ? 1 : 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
220 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
221 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
222 static int fs_test_stat(struct fs_file *_file, struct stat *st_r) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
223 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
224 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
225 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
226 if (file->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
227 fs_set_error_async(_file->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
228 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
229 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
230 if (file->io_failure) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
231 errno = EIO; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
232 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
233 } |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
234 if (!file->exists) { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
235 errno = ENOENT; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
236 return -1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
237 } |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21322
diff
changeset
|
238 i_zero(st_r); |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
239 st_r->st_size = file->contents->used; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
240 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
241 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
242 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
243 static int fs_test_copy(struct fs_file *_src, struct fs_file *_dest) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
244 { |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
245 struct test_fs_file *src; |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
246 struct test_fs_file *dest = (struct test_fs_file *)_dest; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
247 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
248 if (_src != NULL) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
249 dest->copy_src = test_fs_file_get(_src->fs, fs_file_path(_src)); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
250 src = dest->copy_src; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
251 if (dest->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
252 fs_set_error_async(_dest->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
253 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
254 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
255 dest->copy_src = NULL; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
256 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
257 if (dest->io_failure) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
258 errno = EIO; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
259 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
260 } |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
261 if (!src->exists) { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
262 errno = ENOENT; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
263 return -1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
264 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
265 buffer_set_used_size(dest->contents, 0); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
266 buffer_append_buf(dest->contents, src->contents, 0, (size_t)-1); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
267 dest->exists = TRUE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
268 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
269 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
270 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
271 static int fs_test_rename(struct fs_file *_src, struct fs_file *_dest) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
272 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
273 struct test_fs_file *src = (struct test_fs_file *)_src; |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
274 struct test_fs_file *dest = (struct test_fs_file *)_dest; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
275 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
276 if (src->wait_async || dest->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
277 fs_set_error_async(_dest->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
278 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
279 } |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
280 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
281 if (fs_test_copy(_src, _dest) < 0) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
282 return -1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
283 src->exists = FALSE; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
284 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
285 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
286 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
287 static int fs_test_delete(struct fs_file *_file) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
288 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
289 struct test_fs_file *file = (struct test_fs_file *)_file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
290 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
291 if (file->wait_async) { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
292 fs_set_error_async(_file->fs); |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
293 return -1; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
294 } |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
295 |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
296 if (!file->exists) { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
297 errno = ENOENT; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
298 return -1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
299 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
300 return 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
301 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
302 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
303 static struct fs_iter * |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
304 fs_test_iter_init(struct fs *_fs, const char *path, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
305 enum fs_iter_flags flags) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
306 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
307 struct test_fs *fs = (struct test_fs *)_fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
308 struct test_fs_iter *iter; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
309 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
310 iter = i_new(struct test_fs_iter, 1); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
311 iter->iter.fs = _fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
312 iter->iter.flags = flags; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
313 iter->prefix = i_strdup(path); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
314 iter->prefix_len = strlen(iter->prefix); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
315 iter->prev_dir = i_strdup(""); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
316 array_sort(&fs->iter_files, i_strcmp_p); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
317 return &iter->iter; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
318 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
319 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
320 static const char *fs_test_iter_next(struct fs_iter *_iter) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
321 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
322 struct test_fs_iter *iter = (struct test_fs_iter *)_iter; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
323 struct test_fs *fs = (struct test_fs *)_iter->fs; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
324 const char *const *files, *p; |
21322
5ab8dc1a4a6f
global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20548
diff
changeset
|
325 unsigned int count; |
5ab8dc1a4a6f
global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20548
diff
changeset
|
326 size_t len, prev_dir_len = strlen(iter->prev_dir); |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
327 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
328 files = array_get(&fs->iter_files, &count); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
329 for (; iter->idx < count; iter->idx++) { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
330 const char *fname = files[iter->idx]; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
331 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
332 if (strncmp(fname, iter->prefix, iter->prefix_len) != 0) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
333 continue; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
334 p = strrchr(fname, '/'); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
335 if ((_iter->flags & FS_ITER_FLAG_DIRS) == 0) { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
336 if (p == NULL) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
337 return fname; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
338 if (p[1] == '\0') |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
339 continue; /* dir/ */ |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
340 return p+1; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
341 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
342 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
343 if (p == NULL) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
344 continue; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
345 len = p - fname; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
346 if (len == 0) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
347 continue; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
348 if (len == prev_dir_len && |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
349 strncmp(fname, iter->prev_dir, len) == 0) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
350 continue; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
351 i_free(iter->prev_dir); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
352 iter->prev_dir = i_strndup(fname, len); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
353 return iter->prev_dir; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
354 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
355 return NULL; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
356 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
357 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
358 static int fs_test_iter_deinit(struct fs_iter *_iter) |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
359 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
360 struct test_fs_iter *iter = (struct test_fs_iter *)_iter; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
361 int ret = iter->failed ? -1 : 0; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
362 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
363 i_free(iter->prefix); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
364 i_free(iter); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
365 return ret; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
366 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
367 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
368 struct test_fs *test_fs_get(struct fs *fs) |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
369 { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
370 while (strcmp(fs->name, "test") != 0) { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
371 i_assert(fs->parent != NULL); |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
372 fs = fs->parent; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
373 } |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
374 return (struct test_fs *)fs; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
375 } |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
376 |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
377 struct test_fs_file *test_fs_file_get(struct fs *fs, const char *path) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
378 { |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
379 struct fs_file *file; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
380 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
381 fs = &test_fs_get(fs)->fs; |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
382 |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
383 for (file = fs->files;; file = file->next) { |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
384 i_assert(file != NULL); |
20240
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
385 if (strcmp(fs_file_path(file), path) == 0) |
5142d4fbf69b
lib-fs: Improved unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20054
diff
changeset
|
386 break; |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
387 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
388 return (struct test_fs_file *)file; |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
389 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
390 |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
391 const struct fs fs_class_test = { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
392 .name = "test", |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
393 .v = { |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
394 fs_test_alloc, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
395 fs_test_init, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
396 fs_test_deinit, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
397 fs_test_get_properties, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
398 fs_test_file_init, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
399 fs_test_file_deinit, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
400 fs_test_file_close, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
401 fs_test_file_get_path, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
402 fs_test_set_async_callback, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
403 fs_test_wait_async, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
404 fs_test_set_metadata, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
405 fs_test_get_metadata, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
406 fs_test_prefetch, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
407 NULL, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
408 fs_test_read_stream, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
409 NULL, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
410 fs_test_write_stream, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
411 fs_test_write_stream_finish, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
412 fs_test_lock, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
413 fs_test_unlock, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
414 fs_test_exists, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
415 fs_test_stat, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
416 fs_test_copy, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
417 fs_test_rename, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
418 fs_test_delete, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
419 fs_test_iter_init, |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
420 fs_test_iter_next, |
20320
71f46b6a90e8
lib-fs: Added fs_switch_ioloop()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20240
diff
changeset
|
421 fs_test_iter_deinit, |
20548
5f6962a5be0f
lib-fs: Added fs_get_nlinks()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20320
diff
changeset
|
422 NULL, |
5f6962a5be0f
lib-fs: Added fs_get_nlinks()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20320
diff
changeset
|
423 NULL, |
20054
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
424 } |
d2716cb0f3e4
lib-fs: Added fs-test backend for helping with creation of fs-wrapper unit tests.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
diff
changeset
|
425 }; |