|
30 | 30 |
|
31 | 31 | #include <sys/types.h> |
32 | 32 | #include <sys/stat.h> |
| 33 | +#include <errno.h> |
33 | 34 |
|
34 | 35 | #ifdef FLB_SYSTEM_WINDOWS |
35 | 36 | /* Not yet implemented! */ |
@@ -78,7 +79,57 @@ void cb_all() |
78 | 79 | flb_fstore_destroy(fs); |
79 | 80 | } |
80 | 81 |
|
| 82 | +void cb_delete_after_external_close() |
| 83 | +{ |
| 84 | + int ret; |
| 85 | + struct stat st_data; |
| 86 | + struct flb_fstore *fs; |
| 87 | + struct flb_fstore_stream *st; |
| 88 | + struct flb_fstore_file *fsf; |
| 89 | + struct cio_chunk *chunk; |
| 90 | + |
| 91 | + cio_utils_recursive_delete(FSF_STORE_PATH); |
| 92 | + |
| 93 | + fs = flb_fstore_create(FSF_STORE_PATH, FLB_FSTORE_FS); |
| 94 | + TEST_CHECK(fs != NULL); |
| 95 | + if (!fs) { |
| 96 | + return; |
| 97 | + } |
| 98 | + |
| 99 | + st = flb_fstore_stream_create(fs, "abc"); |
| 100 | + TEST_CHECK(st != NULL); |
| 101 | + if (!st) { |
| 102 | + flb_fstore_destroy(fs); |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + fsf = flb_fstore_file_create(fs, st, "example.txt", 100); |
| 107 | + TEST_CHECK(fsf != NULL); |
| 108 | + if (!fsf) { |
| 109 | + flb_fstore_destroy(fs); |
| 110 | + return; |
| 111 | + } |
| 112 | + |
| 113 | + chunk = fsf->chunk; |
| 114 | + TEST_CHECK(chunk != NULL); |
| 115 | + if (!chunk) { |
| 116 | + flb_fstore_destroy(fs); |
| 117 | + return; |
| 118 | + } |
| 119 | + |
| 120 | + cio_chunk_close(chunk, CIO_TRUE); |
| 121 | + |
| 122 | + ret = stat(FSF_STORE_PATH "/abc/example.txt", &st_data); |
| 123 | + TEST_CHECK(ret == -1 && errno == ENOENT); |
| 124 | + |
| 125 | + ret = flb_fstore_file_delete(fs, fsf); |
| 126 | + TEST_CHECK(ret == 0); |
| 127 | + |
| 128 | + flb_fstore_destroy(fs); |
| 129 | +} |
| 130 | + |
81 | 131 | TEST_LIST = { |
82 | 132 | { "all" , cb_all}, |
| 133 | + { "delete_after_external_close", cb_delete_after_external_close}, |
83 | 134 | { NULL } |
84 | 135 | }; |
0 commit comments