Kouhei Sutou
null+****@clear*****
Fri Apr 3 13:20:48 JST 2015
Kouhei Sutou 2015-04-03 13:20:48 +0900 (Fri, 03 Apr 2015) New Revision: 8cee3c1f77a957c26173e50a9525f6944660a6b1 https://github.com/groonga/groonga/commit/8cee3c1f77a957c26173e50a9525f6944660a6b1 Message: dump: support plugin Added files: test/command/suite/dump/schema/plugin/multiple.expected test/command/suite/dump/schema/plugin/multiple.test test/command/suite/dump/schema/plugin/native.expected test/command/suite/dump/schema/plugin/native.test Modified files: lib/proc.c Modified: lib/proc.c (+104 -0) =================================================================== --- lib/proc.c 2015-04-03 00:51:37 +0900 (433ad8e) +++ lib/proc.c 2015-04-03 13:20:48 +0900 (b320f46) @@ -3094,6 +3094,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) { grn_obj *db = ctx->impl->db; @@ -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 Added: test/command/suite/dump/schema/plugin/multiple.expected (+9 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/dump/schema/plugin/multiple.expected 2015-04-03 13:20:48 +0900 (8c8c601) @@ -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 + + Added: test/command/suite/dump/schema/plugin/multiple.test (+4 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/dump/schema/plugin/multiple.test 2015-04-03 13:20:48 +0900 (a465f55) @@ -0,0 +1,4 @@ +plugin_register token_filters/stop_word +plugin_register query_expanders/tsv + +dump Added: test/command/suite/dump/schema/plugin/native.expected (+6 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/dump/schema/plugin/native.expected 2015-04-03 13:20:48 +0900 (6a9bb3b) @@ -0,0 +1,6 @@ +plugin_register token_filters/stop_word +[[0,0.0,0.0],true] +dump +plugin_register token_filters/stop_word + + Added: test/command/suite/dump/schema/plugin/native.test (+3 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/dump/schema/plugin/native.test 2015-04-03 13:20:48 +0900 (64d41ef) @@ -0,0 +1,3 @@ +plugin_register token_filters/stop_word + +dump -------------- next part -------------- HTML����������������������������...Download