Navigation Menu

Skip to content

Commit

Permalink
dump: support plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 3, 2015
1 parent ffb86d4 commit 8cee3c1
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
104 changes: 104 additions & 0 deletions lib/proc.c
Expand Up @@ -3093,6 +3093,108 @@ dump_table(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table,
}\
} while (0)

static void
dump_plugins(grn_ctx *ctx, grn_obj *outbuf)
{
grn_obj *db = ctx->impl->db;
grn_table_cursor *cursor;
grn_id id;
grn_hash *processed_paths;
const char *system_plugins_dir;
const char *plugin_suffix;

cursor = grn_table_cursor_open(ctx, db, NULL, 0, NULL, 0, 0, -1,
GRN_CURSOR_BY_ID);
if (!cursor) {
return;
}

processed_paths = grn_hash_create(ctx, NULL, GRN_HASH_MAX_KEY_SIZE, 0,
GRN_OBJ_TABLE_HASH_KEY |
GRN_OBJ_KEY_VAR_SIZE);
if (!processed_paths) {
grn_table_cursor_close(ctx, cursor);
return;
}

system_plugins_dir = grn_plugin_get_system_plugins_dir();
plugin_suffix = grn_plugin_get_suffix();
while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) {
grn_obj *object;
const char *path;
grn_id processed_path_id;

object = grn_ctx_at(ctx, id);
if (!object) {
ERRCLR(ctx);
continue;
}

if (!grn_obj_is_proc(ctx, object)) {
grn_obj_unlink(ctx, object);
continue;
}

if (grn_obj_is_builtin(ctx, object)) {
grn_obj_unlink(ctx, object);
continue;
}

path = grn_obj_path(ctx, object);
if (!path) {
grn_obj_unlink(ctx, object);
continue;
}

processed_path_id = grn_hash_get(ctx, processed_paths,
path, strlen(path),
NULL);
if (processed_path_id != GRN_ID_NIL) {
grn_obj_unlink(ctx, object);
continue;
}

grn_hash_add(ctx, processed_paths,
path, strlen(path),
NULL, NULL);

{
const char *relative_path;
const char *libs_path = "/.libs/";
const char *start_libs;
char name[PATH_MAX];

name[0] = '\0';
if (strncmp(path, system_plugins_dir, strlen(system_plugins_dir)) == 0) {
relative_path = path + strlen(system_plugins_dir);
} else {
relative_path = path;
}
start_libs = strstr(relative_path, libs_path);
if (start_libs) {
strncat(name, relative_path, start_libs - relative_path);
strcat(name, "/");
strcat(name, start_libs + strlen(libs_path));
} else {
strcat(name, relative_path);
}
if (strlen(name) > strlen(plugin_suffix) &&
strcmp(name + strlen(name) - strlen(plugin_suffix),
plugin_suffix) == 0) {
name[strlen(name) - strlen(plugin_suffix)] = '\0';
}
grn_text_printf(ctx, outbuf, "plugin_register %s\n", name);
}
}
grn_table_cursor_close(ctx, cursor);

if (grn_table_size(ctx, (grn_obj *)processed_paths) > 0) {
GRN_TEXT_PUTC(ctx, outbuf, '\n');
}

grn_hash_close(ctx, processed_paths);
}

static void
dump_schema(grn_ctx *ctx, grn_obj *outbuf)
{
Expand Down Expand Up @@ -3231,6 +3333,8 @@ proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
{
grn_obj *outbuf = ctx->impl->outbuf;
grn_ctx_set_output_type(ctx, GRN_CONTENT_GROONGA_COMMAND_LIST);
dump_plugins(ctx, outbuf);
grn_ctx_output_flush(ctx, 0);
dump_schema(ctx, outbuf);
grn_ctx_output_flush(ctx, 0);
/* To update index columns correctly, we first create the whole schema, then
Expand Down
9 changes: 9 additions & 0 deletions test/command/suite/dump/schema/plugin/multiple.expected
@@ -0,0 +1,9 @@
plugin_register token_filters/stop_word
[[0,0.0,0.0],true]
plugin_register query_expanders/tsv
[[0,0.0,0.0],true]
dump
plugin_register token_filters/stop_word
plugin_register query_expanders/tsv


4 changes: 4 additions & 0 deletions test/command/suite/dump/schema/plugin/multiple.test
@@ -0,0 +1,4 @@
plugin_register token_filters/stop_word
plugin_register query_expanders/tsv

dump
6 changes: 6 additions & 0 deletions test/command/suite/dump/schema/plugin/native.expected
@@ -0,0 +1,6 @@
plugin_register token_filters/stop_word
[[0,0.0,0.0],true]
dump
plugin_register token_filters/stop_word


3 changes: 3 additions & 0 deletions test/command/suite/dump/schema/plugin/native.test
@@ -0,0 +1,3 @@
plugin_register token_filters/stop_word

dump

0 comments on commit 8cee3c1

Please sign in to comment.