Skip to content

Commit bc2a816

Browse files
committed
allow gufi_dir2index to use an optional user-specified plugin
1 parent ccee5bc commit bc2a816

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/gufi_dir2index.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ struct NonDirArgs {
118118

119119
/* list of xattr dbs */
120120
sll_t xattr_db_list;
121+
122+
/*
123+
* an optional opaque pointer to user data for a plugin. if the plugin's db_init() function
124+
* creates and returns a pointer, then the later plugin functions can use it to store state.
125+
*/
126+
void *plugin_user_data;
121127
};
122128

123129
static int process_external(struct input *in, void *args,
@@ -156,19 +162,16 @@ static int process_nondir(struct work *entry, struct entry_data *ed, void *args)
156162
external_read_file(in, entry, process_external, nda->db);
157163
}
158164

159-
/* get entry relative path (use extra buffer to prevent memcpy overlap) */
160-
char relpath[MAXPATH];
161-
const size_t relpath_len = SNFORMAT_S(relpath, MAXPATH, 1,
162-
entry->name + entry->root_parent.len, entry->name_len - entry->root_parent.len);
163-
/* overwrite full path with relative path */
164-
entry->name_len = SNFORMAT_S(entry->name, MAXPATH, 1, relpath, relpath_len);
165-
166165
/* update summary table */
167166
sumit(&nda->summary, ed);
168167

169168
/* add entry + xattr names into bulk insert */
170169
insertdbgo(entry, ed, nda->entries_res);
171170

171+
if (in->plugin_ops->process_file) {
172+
in->plugin_ops->process_file(entry->name, nda->db, nda->plugin_user_data);
173+
}
174+
172175
out:
173176
return rc;
174177
}
@@ -188,6 +191,7 @@ static int processdir(QPTPool_t *ctx, const size_t id, void *data, void *args) {
188191
memset(&nda.ed, 0, sizeof(nda.ed));
189192
nda.topath = NULL;
190193
nda.ed.type = 'd';
194+
nda.plugin_user_data = NULL;
191195

192196
DIR *dir = NULL;
193197

@@ -269,6 +273,14 @@ static int processdir(QPTPool_t *ctx, const size_t id, void *data, void *args) {
269273
}
270274

271275
startdb(nda.db);
276+
277+
if (pa->in.plugin_ops->db_init) {
278+
nda.plugin_user_data = pa->in.plugin_ops->db_init(nda.db);
279+
}
280+
}
281+
282+
if (pa->in.plugin_ops->process_dir) {
283+
pa->in.plugin_ops->process_dir(nda.work->name, nda.db, nda.plugin_user_data);
272284
}
273285

274286
struct descend_counters ctrs;
@@ -277,6 +289,10 @@ static int processdir(QPTPool_t *ctx, const size_t id, void *data, void *args) {
277289
&ctrs);
278290

279291
if (process_dbdb) {
292+
if (pa->in.plugin_ops->db_exit) {
293+
pa->in.plugin_ops->db_exit(nda.db, nda.plugin_user_data);
294+
}
295+
280296
stopdb(nda.db);
281297

282298
/* entries and xattrs have been inserted */
@@ -407,7 +423,7 @@ static void sub_help(void) {
407423

408424
int main(int argc, char *argv[]) {
409425
struct PoolArgs pa;
410-
process_args_and_maybe_exit("hHvn:xy:z:k:M:s:C:" COMPRESS_OPT "q", 2, "input_dir... output_dir", &pa.in);
426+
process_args_and_maybe_exit("hHvn:xy:z:k:M:s:C:U:" COMPRESS_OPT "q", 2, "input_dir... output_dir", &pa.in);
411427

412428
/* parse positional args, following the options */
413429
/* does not have to be canonicalized */

0 commit comments

Comments
 (0)