isomorfeus-ferret 0.17.2 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/ext/isomorfeus_ferret_ext/benchmark.c +9 -20
  3. data/ext/isomorfeus_ferret_ext/benchmarks_all.h +1 -2
  4. data/ext/isomorfeus_ferret_ext/bm_hash.c +1 -2
  5. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +4 -2
  6. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +3 -2
  7. data/ext/isomorfeus_ferret_ext/frb_analysis.c +4 -5
  8. data/ext/isomorfeus_ferret_ext/frb_field_info.c +3 -4
  9. data/ext/isomorfeus_ferret_ext/frb_index.c +118 -125
  10. data/ext/isomorfeus_ferret_ext/frb_lazy_doc.c +14 -16
  11. data/ext/isomorfeus_ferret_ext/frb_search.c +31 -23
  12. data/ext/isomorfeus_ferret_ext/frb_store.c +27 -13
  13. data/ext/isomorfeus_ferret_ext/frb_utils.c +3 -6
  14. data/ext/isomorfeus_ferret_ext/frt_analysis.c +39 -46
  15. data/ext/isomorfeus_ferret_ext/frt_analysis.h +9 -9
  16. data/ext/isomorfeus_ferret_ext/frt_array.c +11 -22
  17. data/ext/isomorfeus_ferret_ext/frt_bitvector.h +3 -6
  18. data/ext/isomorfeus_ferret_ext/frt_doc_field.c +87 -0
  19. data/ext/isomorfeus_ferret_ext/frt_doc_field.h +26 -0
  20. data/ext/isomorfeus_ferret_ext/frt_document.c +4 -97
  21. data/ext/isomorfeus_ferret_ext/frt_document.h +2 -27
  22. data/ext/isomorfeus_ferret_ext/frt_except.c +8 -6
  23. data/ext/isomorfeus_ferret_ext/frt_except.h +1 -2
  24. data/ext/isomorfeus_ferret_ext/frt_field_index.c +13 -32
  25. data/ext/isomorfeus_ferret_ext/frt_field_index.h +0 -6
  26. data/ext/isomorfeus_ferret_ext/frt_field_info.c +69 -0
  27. data/ext/isomorfeus_ferret_ext/frt_field_info.h +49 -0
  28. data/ext/isomorfeus_ferret_ext/frt_field_infos.c +196 -0
  29. data/ext/isomorfeus_ferret_ext/frt_field_infos.h +35 -0
  30. data/ext/isomorfeus_ferret_ext/frt_global.c +10 -4
  31. data/ext/isomorfeus_ferret_ext/frt_global.h +11 -15
  32. data/ext/isomorfeus_ferret_ext/frt_hash.c +8 -8
  33. data/ext/isomorfeus_ferret_ext/frt_hash.h +1 -2
  34. data/ext/isomorfeus_ferret_ext/frt_hashset.c +20 -40
  35. data/ext/isomorfeus_ferret_ext/frt_hashset.h +1 -2
  36. data/ext/isomorfeus_ferret_ext/frt_helper.c +7 -15
  37. data/ext/isomorfeus_ferret_ext/frt_in_stream.c +35 -45
  38. data/ext/isomorfeus_ferret_ext/frt_in_stream.h +3 -2
  39. data/ext/isomorfeus_ferret_ext/frt_ind.c +20 -38
  40. data/ext/isomorfeus_ferret_ext/frt_index.c +292 -790
  41. data/ext/isomorfeus_ferret_ext/frt_index.h +1 -102
  42. data/ext/isomorfeus_ferret_ext/frt_lang.c +5 -10
  43. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.c +3 -3
  44. data/ext/isomorfeus_ferret_ext/frt_lazy_doc.h +1 -1
  45. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.c +18 -25
  46. data/ext/isomorfeus_ferret_ext/frt_lazy_doc_field.h +5 -5
  47. data/ext/isomorfeus_ferret_ext/frt_mdbx_store.c +102 -70
  48. data/ext/isomorfeus_ferret_ext/frt_mempool.c +8 -16
  49. data/ext/isomorfeus_ferret_ext/frt_multimapper.c +23 -46
  50. data/ext/isomorfeus_ferret_ext/frt_multimapper.h +4 -8
  51. data/ext/isomorfeus_ferret_ext/frt_out_stream.c +31 -43
  52. data/ext/isomorfeus_ferret_ext/frt_out_stream.h +2 -2
  53. data/ext/isomorfeus_ferret_ext/frt_posh.c +6 -819
  54. data/ext/isomorfeus_ferret_ext/frt_posh.h +0 -57
  55. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +11 -22
  56. data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +1 -2
  57. data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +85 -171
  58. data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +8 -16
  59. data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +1 -2
  60. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +49 -98
  61. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +52 -104
  62. data/ext/isomorfeus_ferret_ext/frt_q_range.c +6 -12
  63. data/ext/isomorfeus_ferret_ext/frt_q_span.c +113 -226
  64. data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +1 -2
  65. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +134 -85
  66. data/ext/isomorfeus_ferret_ext/frt_search.c +82 -164
  67. data/ext/isomorfeus_ferret_ext/frt_similarity.c +11 -22
  68. data/ext/isomorfeus_ferret_ext/frt_similarity.h +1 -2
  69. data/ext/isomorfeus_ferret_ext/frt_store.c +13 -25
  70. data/ext/isomorfeus_ferret_ext/frt_store.h +86 -52
  71. data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +8 -16
  72. data/ext/isomorfeus_ferret_ext/frt_win32.h +5 -10
  73. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +12 -11
  74. data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +11 -13
  75. data/ext/isomorfeus_ferret_ext/lz4.c +422 -195
  76. data/ext/isomorfeus_ferret_ext/lz4.h +114 -46
  77. data/ext/isomorfeus_ferret_ext/lz4frame.c +421 -242
  78. data/ext/isomorfeus_ferret_ext/lz4frame.h +122 -53
  79. data/ext/isomorfeus_ferret_ext/lz4hc.c +127 -111
  80. data/ext/isomorfeus_ferret_ext/lz4hc.h +14 -14
  81. data/ext/isomorfeus_ferret_ext/lz4xxhash.h +1 -1
  82. data/ext/isomorfeus_ferret_ext/mdbx.c +3762 -2526
  83. data/ext/isomorfeus_ferret_ext/mdbx.h +115 -70
  84. data/ext/isomorfeus_ferret_ext/test.c +40 -87
  85. data/ext/isomorfeus_ferret_ext/test.h +3 -6
  86. data/ext/isomorfeus_ferret_ext/test_1710.c +11 -13
  87. data/ext/isomorfeus_ferret_ext/test_analysis.c +32 -64
  88. data/ext/isomorfeus_ferret_ext/test_array.c +6 -12
  89. data/ext/isomorfeus_ferret_ext/test_bitvector.c +12 -24
  90. data/ext/isomorfeus_ferret_ext/test_document.c +23 -33
  91. data/ext/isomorfeus_ferret_ext/test_except.c +10 -21
  92. data/ext/isomorfeus_ferret_ext/test_fields.c +62 -68
  93. data/ext/isomorfeus_ferret_ext/test_file_deleter.c +15 -23
  94. data/ext/isomorfeus_ferret_ext/test_filter.c +17 -27
  95. data/ext/isomorfeus_ferret_ext/test_global.c +14 -29
  96. data/ext/isomorfeus_ferret_ext/test_hash.c +19 -38
  97. data/ext/isomorfeus_ferret_ext/test_hashset.c +8 -16
  98. data/ext/isomorfeus_ferret_ext/test_helper.c +4 -8
  99. data/ext/isomorfeus_ferret_ext/test_highlighter.c +16 -28
  100. data/ext/isomorfeus_ferret_ext/test_index.c +277 -487
  101. data/ext/isomorfeus_ferret_ext/test_lang.c +7 -14
  102. data/ext/isomorfeus_ferret_ext/test_mdbx_store.c +2 -5
  103. data/ext/isomorfeus_ferret_ext/test_mempool.c +5 -10
  104. data/ext/isomorfeus_ferret_ext/test_multimapper.c +3 -6
  105. data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +9 -18
  106. data/ext/isomorfeus_ferret_ext/test_q_const_score.c +4 -6
  107. data/ext/isomorfeus_ferret_ext/test_q_filtered.c +3 -4
  108. data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +9 -15
  109. data/ext/isomorfeus_ferret_ext/test_q_parser.c +8 -16
  110. data/ext/isomorfeus_ferret_ext/test_q_span.c +19 -35
  111. data/ext/isomorfeus_ferret_ext/test_ram_store.c +14 -13
  112. data/ext/isomorfeus_ferret_ext/test_search.c +60 -109
  113. data/ext/isomorfeus_ferret_ext/test_segments.c +8 -13
  114. data/ext/isomorfeus_ferret_ext/test_similarity.c +2 -4
  115. data/ext/isomorfeus_ferret_ext/test_sort.c +14 -24
  116. data/ext/isomorfeus_ferret_ext/test_store.c +96 -115
  117. data/ext/isomorfeus_ferret_ext/test_term.c +9 -15
  118. data/ext/isomorfeus_ferret_ext/test_term_vectors.c +9 -14
  119. data/ext/isomorfeus_ferret_ext/test_test.c +4 -8
  120. data/ext/isomorfeus_ferret_ext/test_threading.c +14 -20
  121. data/ext/isomorfeus_ferret_ext/testhelper.c +11 -21
  122. data/ext/isomorfeus_ferret_ext/testhelper.h +1 -1
  123. data/ext/isomorfeus_ferret_ext/tests_all.h +1 -2
  124. data/lib/isomorfeus/ferret/index/index.rb +1 -1
  125. data/lib/isomorfeus/ferret/version.rb +1 -1
  126. 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 ram_touch(FrtStore *store, const char *filename) {
36
- if (frt_h_get(store->dir.ht, filename) == NULL) {
37
- frt_h_set(store->dir.ht, filename, rf_new(filename));
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 int ram_exists(FrtStore *store, const char *filename) {
42
- if (frt_h_get(store->dir.ht, filename) != NULL) {
43
- return true;
44
- } else {
45
- return false;
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 ram_remove(FrtStore *store, const char *filename) {
50
- FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, filename, false);
51
- if (rf != NULL) {
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 void ram_rename(FrtStore *store, const char *from, const char *to) {
60
- FrtRAMFile *rf = (FrtRAMFile *)frt_h_rem(store->dir.ht, from, false);
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(store->dir.ht, to);
90
+ tmp = (FrtRAMFile *)frt_h_get(folder, to);
74
91
  if (tmp != NULL) {
75
- frt_h_del(store->dir.ht, to);
92
+ frt_h_del(folder, to);
76
93
  }
77
94
 
78
- frt_h_set(store->dir.ht, rf->name, rf);
95
+ frt_h_set(folder, rf->name, rf);
79
96
  }
80
97
 
81
- static int ram_count(FrtStore *store) {
82
- return store->dir.ht->size;
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 *ht = store->dir.ht;
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 <= ht->mask; i++) {
89
- FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
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
- FrtHash *ht = store->dir.ht;
109
- for (i = 0; i <= ht->mask; i++) {
110
- FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
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(ht, rf->name);
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
- FrtHash *ht = store->dir.ht;
120
- for (i = 0; i <= ht->mask; i++) {
121
- FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
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(ht, rf->name);
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
- FrtHash *ht = store->dir.ht;
131
- for (i = 0; i <= ht->mask; i++) {
132
- FrtRAMFile *rf = (FrtRAMFile *)ht->table[i].value;
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(ht, rf->name);
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
- FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
141
- if (rf != NULL) {
142
- return rf->len;
143
- } else {
144
- return 0;
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
- FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
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(store->dir.ht, rf->name, rf);
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
- FrtRAMFile *rf = (FrtRAMFile *)frt_h_get(store->dir.ht, filename);
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->name);
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 = frt_h_new_str(NULL, rf_close);
356
- new_store->touch = &ram_touch;
357
- new_store->exists = &ram_exists;
358
- new_store->remove = &ram_remove;
359
- new_store->rename = &ram_rename;
360
- new_store->count = &ram_count;
361
- new_store->clear = &ram_clear;
362
- new_store->clear_all = &ram_clear_all;
363
- new_store->clear_locks = &ram_clear_locks;
364
- new_store->length = &ram_length;
365
- new_store->each = &ram_each;
366
- new_store->new_output = &ram_new_output;
367
- new_store->open_input = &ram_open_input;
368
- new_store->open_lock_i = &ram_open_lock_i;
369
- new_store->close_lock_i = &ram_close_lock_i;
370
- new_store->close_i = &ram_close_i;
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
- FrtStore *to_store, *from_store;
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 *store, FrtStore *from_store, bool close_dir) {
394
- store = frt_open_ram_store(store);
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.to_store = store;
443
+ cfa.folder_name = folder_name;
444
+ cfa.to_store = to_store;
397
445
  cfa.from_store = from_store;
398
446
 
399
- from_store->each(from_store, &copy_files, &cfa);
447
+ to_store->create_folder(to_store, folder_name);
448
+ from_store->each(from_store, folder_name, &copy_files, &cfa);
400
449
 
401
- if (close_dir) {
450
+ if (close_store) {
402
451
  frt_store_close(from_store);
403
452
  }
404
453
 
405
- return store;
454
+ return to_store;
406
455
  }