isomorfeus-ferret 0.17.2 → 0.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
- data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
- data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
- data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
- data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
- data/ext/isomorfeus_ferret_ext/frb_index.c +118 -125
- data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
- data/ext/isomorfeus_ferret_ext/frb_search.c +31 -23
- data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
- data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
- data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
- data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
- data/ext/isomorfeus_ferret_ext/frt_document.h +2 -27
- data/ext/isomorfeus_ferret_ext/frt_except.c +8 -6
- data/ext/isomorfeus_ferret_ext/frt_except.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +13 -32
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
- data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
- data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
- data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
- data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
- data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
- data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
- data/ext/isomorfeus_ferret_ext/frt_in_stream.c +35 -45
- data/ext/isomorfeus_ferret_ext/frt_in_stream.h +3 -2
- data/ext/isomorfeus_ferret_ext/frt_ind.c +20 -38
- data/ext/isomorfeus_ferret_ext/frt_index.c +292 -790
- data/ext/isomorfeus_ferret_ext/frt_index.h +1 -102
- data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +3 -3
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +1 -1
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +18 -25
- data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +5 -5
- data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
- data/ext/isomorfeus_ferret_ext/frt_out_stream.c +31 -43
- data/ext/isomorfeus_ferret_ext/frt_out_stream.h +2 -2
- data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
- data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +85 -171
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +52 -104
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +6 -12
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +113 -226
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
- data/ext/isomorfeus_ferret_ext/frt_search.c +82 -164
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +11 -22
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
- data/ext/isomorfeus_ferret_ext/frt_store.c +13 -25
- data/ext/isomorfeus_ferret_ext/frt_store.h +86 -52
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
- data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
- data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
- data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
- data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
- data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
- data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
- data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
- data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
- data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
- data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
- data/ext/isomorfeus_ferret_ext/test.c +40 -87
- data/ext/isomorfeus_ferret_ext/test.h +3 -6
- data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
- data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
- data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
- data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
- data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
- data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +15 -23
- data/ext/isomorfeus_ferret_ext/test_filter.c +17 -27
- data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
- data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
- data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
- data/ext/isomorfeus_ferret_ext/test_index.c +277 -487
- data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
- data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
- data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
- data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
- data/ext/isomorfeus_ferret_ext/test_search.c +60 -109
- data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
- data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
- data/ext/isomorfeus_ferret_ext/test_sort.c +14 -24
- data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
- data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
- data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
- data/ext/isomorfeus_ferret_ext/test_threading.c +14 -20
- data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
- data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
- data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
- data/lib/isomorfeus/ferret/index/index.rb +1 -1
- data/lib/isomorfeus/ferret/version.rb +1 -1
- metadata +24 -4
@@ -86,8 +86,7 @@ static FrtQuery *wcq_rewrite(FrtQuery *self, FrtIndexReader *ir) {
|
|
86
86
|
if (NULL == first_star && NULL == first_ques) {
|
87
87
|
q = frt_tq_new(WCQ(self)->field, pattern);
|
88
88
|
q->boost = self->boost;
|
89
|
-
}
|
90
|
-
else {
|
89
|
+
} else {
|
91
90
|
const int field_num = frt_fis_get_field_num(ir->fis, WCQ(self)->field);
|
92
91
|
q = frt_multi_tq_new_conf(WCQ(self)->field, FrtMTQMaxTerms(self), 0.0);
|
93
92
|
|
@@ -32,37 +32,54 @@ void rf_close(void *p) {
|
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
|
-
static void
|
36
|
-
if (frt_h_get(store->dir.ht,
|
37
|
-
frt_h_set(store->dir.ht,
|
35
|
+
static void ram_create_folder(FrtStore *store, const char *folder_name) {
|
36
|
+
if (frt_h_get(store->dir.ht, folder_name) == NULL) {
|
37
|
+
frt_h_set(store->dir.ht, frt_estrdup(folder_name), frt_h_new_str(NULL, rf_close));
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
41
|
-
static
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
static void ram_remove_folder(FrtStore *store, const char *folder_name) {
|
42
|
+
frt_h_rem(store->dir.ht, folder_name, true);
|
43
|
+
}
|
44
|
+
|
45
|
+
static void ram_touch(FrtStore *store, const char *folder_name, const char *filename) {
|
46
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
47
|
+
if (folder && frt_h_get(folder, filename) == NULL) {
|
48
|
+
frt_h_set(folder, filename, rf_new(filename));
|
46
49
|
}
|
47
50
|
}
|
48
51
|
|
49
|
-
static int
|
50
|
-
|
51
|
-
if (
|
52
|
-
rf_close(rf);
|
52
|
+
static int ram_exists(FrtStore *store, const char *folder_name, const char *filename) {
|
53
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
54
|
+
if (folder && frt_h_get(folder, filename) != NULL) {
|
53
55
|
return true;
|
54
|
-
} else {
|
55
|
-
return false;
|
56
56
|
}
|
57
|
+
return false;
|
57
58
|
}
|
58
59
|
|
59
|
-
static
|
60
|
-
|
60
|
+
static int ram_remove(FrtStore *store, const char *folder_name, const char *filename) {
|
61
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
62
|
+
if (folder) {
|
63
|
+
FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(folder, filename, false);
|
64
|
+
if (rf != NULL) {
|
65
|
+
rf_close(rf);
|
66
|
+
return true;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
|
72
|
+
static void ram_rename(FrtStore *store, const char *folder_name, const char *from, const char *to) {
|
61
73
|
FrtRAMFile *tmp;
|
74
|
+
FrtRAMFile *rf = NULL;
|
75
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
62
76
|
|
77
|
+
if (folder) {
|
78
|
+
rf = (FrtRAMFile *)frt_h_rem(folder, from, false);
|
79
|
+
}
|
80
|
+
|
63
81
|
if (rf == NULL) {
|
64
|
-
FRT_RAISE(FRT_IO_ERROR, "couldn't rename \"%s\" to \"%s\". \"%s\""
|
65
|
-
" doesn't exist", from, to, from);
|
82
|
+
FRT_RAISE(FRT_IO_ERROR, "couldn't rename \"%s\" to \"%s\". \"%s\" doesn't exist", from, to, from);
|
66
83
|
}
|
67
84
|
|
68
85
|
free(rf->name);
|
@@ -70,23 +87,26 @@ static void ram_rename(FrtStore *store, const char *from, const char *to) {
|
|
70
87
|
rf->name = frt_estrdup(to);
|
71
88
|
|
72
89
|
/* clean up the file we are overwriting */
|
73
|
-
tmp = (FrtRAMFile *)frt_h_get(
|
90
|
+
tmp = (FrtRAMFile *)frt_h_get(folder, to);
|
74
91
|
if (tmp != NULL) {
|
75
|
-
frt_h_del(
|
92
|
+
frt_h_del(folder, to);
|
76
93
|
}
|
77
94
|
|
78
|
-
frt_h_set(
|
95
|
+
frt_h_set(folder, rf->name, rf);
|
79
96
|
}
|
80
97
|
|
81
|
-
static int ram_count(FrtStore *store) {
|
82
|
-
|
98
|
+
static int ram_count(FrtStore *store, const char *folder_name) {
|
99
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
100
|
+
if (!folder) { return 0; }
|
101
|
+
return folder->size;
|
83
102
|
}
|
84
103
|
|
85
|
-
static void ram_each(FrtStore *store, void (*func)(const char *fname, void *arg), void *arg) {
|
86
|
-
FrtHash *
|
104
|
+
static void ram_each(FrtStore *store, const char *folder_name, void (*func)(const char *fname, void *arg), void *arg) {
|
105
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
106
|
+
if (!folder) { return; }
|
87
107
|
int i;
|
88
|
-
for (i = 0; i <=
|
89
|
-
FrtRAMFile *rf = (FrtRAMFile *)
|
108
|
+
for (i = 0; i <= folder->mask; i++) {
|
109
|
+
FrtRAMFile *rf = (FrtRAMFile *)folder->table[i].value;
|
90
110
|
if (rf) {
|
91
111
|
if (strncmp(rf->name, FRT_LOCK_PREFIX, strlen(FRT_LOCK_PREFIX)) == 0) {
|
92
112
|
continue;
|
@@ -103,46 +123,51 @@ static void ram_close_i(FrtStore *store) {
|
|
103
123
|
/*
|
104
124
|
* Be sure to keep the locks
|
105
125
|
*/
|
106
|
-
static void ram_clear(FrtStore *store) {
|
126
|
+
static void ram_clear(FrtStore *store, const char *folder_name) {
|
127
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
107
128
|
int i;
|
108
|
-
|
109
|
-
for (i = 0; i <=
|
110
|
-
FrtRAMFile *rf = (FrtRAMFile *)
|
129
|
+
if (!folder) { return; }
|
130
|
+
for (i = 0; i <= folder->mask; i++) {
|
131
|
+
FrtRAMFile *rf = (FrtRAMFile *)folder->table[i].value;
|
111
132
|
if (rf && !frt_file_is_lock(rf->name)) {
|
112
|
-
frt_h_del(
|
133
|
+
frt_h_del(folder, rf->name);
|
113
134
|
}
|
114
135
|
}
|
115
136
|
}
|
116
137
|
|
117
|
-
static void ram_clear_locks(FrtStore *store) {
|
138
|
+
static void ram_clear_locks(FrtStore *store, const char *folder_name) {
|
139
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
118
140
|
int i;
|
119
|
-
|
120
|
-
for (i = 0; i <=
|
121
|
-
FrtRAMFile *rf = (FrtRAMFile *)
|
141
|
+
if (!folder) { return; }
|
142
|
+
for (i = 0; i <= folder->mask; i++) {
|
143
|
+
FrtRAMFile *rf = (FrtRAMFile *)folder->table[i].value;
|
122
144
|
if (rf && frt_file_is_lock(rf->name)) {
|
123
|
-
frt_h_del(
|
145
|
+
frt_h_del(folder, rf->name);
|
124
146
|
}
|
125
147
|
}
|
126
148
|
}
|
127
149
|
|
128
|
-
static void ram_clear_all(FrtStore *store) {
|
150
|
+
static void ram_clear_all(FrtStore *store, const char *folder_name) {
|
151
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
129
152
|
int i;
|
130
|
-
|
131
|
-
for (i = 0; i <=
|
132
|
-
FrtRAMFile *rf = (FrtRAMFile *)
|
153
|
+
if (!folder) { return; }
|
154
|
+
for (i = 0; i <= folder->mask; i++) {
|
155
|
+
FrtRAMFile *rf = (FrtRAMFile *)folder->table[i].value;
|
133
156
|
if (rf) {
|
134
|
-
frt_h_del(
|
157
|
+
frt_h_del(folder, rf->name);
|
135
158
|
}
|
136
159
|
}
|
137
160
|
}
|
138
161
|
|
139
|
-
static frt_off_t ram_length(FrtStore *store, const char *filename) {
|
140
|
-
|
141
|
-
if (
|
142
|
-
|
143
|
-
|
144
|
-
|
162
|
+
static frt_off_t ram_length(FrtStore *store, const char *folder_name, const char *filename) {
|
163
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
164
|
+
if (folder) {
|
165
|
+
FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(folder, filename);
|
166
|
+
if (rf) {
|
167
|
+
return rf->len;
|
168
|
+
}
|
145
169
|
}
|
170
|
+
return 0;
|
146
171
|
}
|
147
172
|
|
148
173
|
void ramo_flush_i(FrtOutStream *os, const frt_uchar *src, int len) {
|
@@ -227,15 +252,23 @@ void frt_ram_destroy_buffer(FrtOutStream *os) {
|
|
227
252
|
free(os);
|
228
253
|
}
|
229
254
|
|
230
|
-
static FrtOutStream *ram_new_output(FrtStore *store, const char *filename) {
|
231
|
-
|
255
|
+
static FrtOutStream *ram_new_output(FrtStore *store, const char *folder_name, const char *filename) {
|
256
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
257
|
+
|
258
|
+
if (!folder) {
|
259
|
+
FRT_RAISE(FRT_FILE_NOT_FOUND_ERROR, "tried to open \"%s\" in folder \"%s\", but folder it doesn't exist", filename, folder_name);
|
260
|
+
}
|
261
|
+
|
262
|
+
FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(folder, filename);
|
232
263
|
FrtOutStream *os = frt_os_new();
|
233
264
|
|
234
265
|
if (rf == NULL) {
|
235
266
|
rf = rf_new(filename);
|
236
|
-
frt_h_set(
|
267
|
+
frt_h_set(folder, rf->name, rf);
|
237
268
|
}
|
238
269
|
FRT_REF(rf);
|
270
|
+
|
271
|
+
os->folder_name = frt_estrdup(folder_name);
|
239
272
|
os->pointer = 0;
|
240
273
|
os->file.rf = rf;
|
241
274
|
os->m = &RAM_OUT_STREAM_METHODS;
|
@@ -291,15 +324,23 @@ static const struct FrtInStreamMethods RAM_IN_STREAM_METHODS = {
|
|
291
324
|
rami_close_i
|
292
325
|
};
|
293
326
|
|
294
|
-
static FrtInStream *ram_open_input(FrtStore *store, const char *filename) {
|
295
|
-
|
327
|
+
static FrtInStream *ram_open_input(FrtStore *store, const char* folder_name, const char *filename) {
|
328
|
+
FrtHash *folder = frt_h_get(store->dir.ht, folder_name);
|
329
|
+
|
330
|
+
if (!folder) {
|
331
|
+
FRT_RAISE(FRT_FILE_NOT_FOUND_ERROR, "tried to open \"%s\" in folder \"%s\", but folder it doesn't exist", filename, folder_name);
|
332
|
+
}
|
333
|
+
|
334
|
+
FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(folder, filename);
|
296
335
|
FrtInStream *is = NULL;
|
297
336
|
|
298
337
|
if (rf == NULL) {
|
299
|
-
FRT_RAISE(FRT_FILE_NOT_FOUND_ERROR, "tried to open \"%s\" but it doesn't exist", filename);
|
338
|
+
FRT_RAISE(FRT_FILE_NOT_FOUND_ERROR, "tried to open \"%s\", but it doesn't exist", filename);
|
300
339
|
}
|
340
|
+
|
301
341
|
FRT_REF(rf);
|
302
342
|
is = frt_is_new();
|
343
|
+
is->folder_name = frt_estrdup(folder_name);
|
303
344
|
is->f->file.rf = rf;
|
304
345
|
is->f->ref_cnt = 1;
|
305
346
|
is->d.pointer = 0;
|
@@ -312,25 +353,26 @@ static FrtInStream *ram_open_input(FrtStore *store, const char *filename) {
|
|
312
353
|
|
313
354
|
static int ram_lock_obtain(FrtLock *lock) {
|
314
355
|
int ret = true;
|
315
|
-
if (ram_exists(lock->store, lock->name)) {
|
356
|
+
if (ram_exists(lock->store, lock->folder_name, lock->name)) {
|
316
357
|
ret = false;
|
317
358
|
}
|
318
|
-
ram_touch(lock->store, lock->name);
|
359
|
+
ram_touch(lock->store, lock->folder_name, lock->name);
|
319
360
|
return ret;
|
320
361
|
}
|
321
362
|
|
322
363
|
static int ram_lock_is_locked(FrtLock *lock) {
|
323
|
-
return ram_exists(lock->store, lock->name);
|
364
|
+
return ram_exists(lock->store, lock->folder_name, lock->name);
|
324
365
|
}
|
325
366
|
|
326
367
|
static void ram_lock_release(FrtLock *lock) {
|
327
|
-
ram_remove(lock->store, lock->name);
|
368
|
+
ram_remove(lock->store, lock->folder_name, lock->name);
|
328
369
|
}
|
329
370
|
|
330
|
-
static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname) {
|
371
|
+
static FrtLock *ram_open_lock_i(FrtStore *store, const char *folder_name, const char *lockname) {
|
331
372
|
FrtLock *lock = FRT_ALLOC(FrtLock);
|
332
373
|
char lname[100];
|
333
374
|
snprintf(lname, 100, "%s%s.lck", FRT_LOCK_PREFIX, lockname);
|
375
|
+
lock->folder_name = frt_estrdup(folder_name);
|
334
376
|
lock->name = frt_estrdup(lname);
|
335
377
|
lock->store = store;
|
336
378
|
FRT_REF(store);
|
@@ -343,7 +385,8 @@ static FrtLock *ram_open_lock_i(FrtStore *store, const char *lockname) {
|
|
343
385
|
|
344
386
|
static void ram_close_lock_i(FrtLock *lock) {
|
345
387
|
FRT_DEREF(lock->store);
|
346
|
-
free(lock->
|
388
|
+
free((void *)lock->folder_name);
|
389
|
+
free((void *)lock->name);
|
347
390
|
free(lock);
|
348
391
|
}
|
349
392
|
|
@@ -352,33 +395,37 @@ FrtStore *frt_open_ram_store(FrtStore *new_store) {
|
|
352
395
|
new_store = frt_store_alloc();
|
353
396
|
frt_store_init(new_store);
|
354
397
|
|
355
|
-
new_store->dir.ht
|
356
|
-
new_store->
|
357
|
-
new_store->
|
358
|
-
new_store->
|
359
|
-
new_store->
|
360
|
-
new_store->
|
361
|
-
new_store->
|
362
|
-
new_store->
|
363
|
-
new_store->
|
364
|
-
new_store->
|
365
|
-
new_store->
|
366
|
-
new_store->
|
367
|
-
new_store->
|
368
|
-
new_store->
|
369
|
-
new_store->
|
370
|
-
new_store->
|
398
|
+
new_store->dir.ht = frt_h_new_str(free, (void (*)(void *))frt_h_destroy);
|
399
|
+
new_store->create_folder = &ram_create_folder;
|
400
|
+
new_store->remove_folder = &ram_remove_folder;
|
401
|
+
new_store->touch = &ram_touch;
|
402
|
+
new_store->exists = &ram_exists;
|
403
|
+
new_store->remove = &ram_remove;
|
404
|
+
new_store->rename = &ram_rename;
|
405
|
+
new_store->count = &ram_count;
|
406
|
+
new_store->clear = &ram_clear;
|
407
|
+
new_store->clear_all = &ram_clear_all;
|
408
|
+
new_store->clear_locks = &ram_clear_locks;
|
409
|
+
new_store->length = &ram_length;
|
410
|
+
new_store->each = &ram_each;
|
411
|
+
new_store->new_output = &ram_new_output;
|
412
|
+
new_store->open_input = &ram_open_input;
|
413
|
+
new_store->open_lock_i = &ram_open_lock_i;
|
414
|
+
new_store->close_lock_i = &ram_close_lock_i;
|
415
|
+
new_store->close_i = &ram_close_i;
|
371
416
|
return new_store;
|
372
417
|
}
|
373
418
|
|
374
419
|
struct CopyFileArg {
|
375
|
-
|
420
|
+
const char *folder_name;
|
421
|
+
FrtStore *to_store;
|
422
|
+
FrtStore *from_store;
|
376
423
|
};
|
377
424
|
|
378
425
|
static void copy_files(const char *fname, void *arg) {
|
379
426
|
struct CopyFileArg *cfa = (struct CopyFileArg *)arg;
|
380
|
-
FrtOutStream *os = cfa->to_store->new_output(cfa->to_store, fname);
|
381
|
-
FrtInStream *is = cfa->from_store->open_input(cfa->from_store, fname);
|
427
|
+
FrtOutStream *os = cfa->to_store->new_output(cfa->to_store, cfa->folder_name, fname);
|
428
|
+
FrtInStream *is = cfa->from_store->open_input(cfa->from_store, cfa->folder_name, fname);
|
382
429
|
int len = (int)frt_is_length(is);
|
383
430
|
frt_uchar *buffer = FRT_ALLOC_N(frt_uchar, len + 1);
|
384
431
|
|
@@ -390,17 +437,19 @@ static void copy_files(const char *fname, void *arg) {
|
|
390
437
|
free(buffer);
|
391
438
|
}
|
392
439
|
|
393
|
-
FrtStore *frt_open_ram_store_and_copy(FrtStore *
|
394
|
-
|
440
|
+
FrtStore *frt_open_ram_store_and_copy(FrtStore *to_store, FrtStore *from_store, const char *folder_name, bool close_store) {
|
441
|
+
to_store = frt_open_ram_store(to_store);
|
395
442
|
struct CopyFileArg cfa;
|
396
|
-
cfa.
|
443
|
+
cfa.folder_name = folder_name;
|
444
|
+
cfa.to_store = to_store;
|
397
445
|
cfa.from_store = from_store;
|
398
446
|
|
399
|
-
|
447
|
+
to_store->create_folder(to_store, folder_name);
|
448
|
+
from_store->each(from_store, folder_name, ©_files, &cfa);
|
400
449
|
|
401
|
-
if (
|
450
|
+
if (close_store) {
|
402
451
|
frt_store_close(from_store);
|
403
452
|
}
|
404
453
|
|
405
|
-
return
|
454
|
+
return to_store;
|
406
455
|
}
|