null+****@clear*****
null+****@clear*****
2011年 5月 15日 (日) 23:50:28 JST
Kouhei Sutou 2011-05-15 14:50:28 +0000 (Sun, 15 May 2011)
New Revision: 07df09f726fe7bdc60cb3dd7ac4af8e5710e598c
Log:
[plugin] register command accepts absolute plugin path.
Modified files:
lib/plugin.c
test/unit/core/test-plugin.c
Modified: lib/plugin.c (+12 -8)
===================================================================
--- lib/plugin.c 2011-05-15 14:47:48 +0000 (61ef742)
+++ lib/plugin.c 2011-05-15 14:50:28 +0000 (8e1039e)
@@ -355,15 +355,19 @@ grn_plugin_register(grn_ctx *ctx, const char *name)
char normalized_name[PATH_MAX];
int name_length, max_name_length;
- plugins_dir = getenv("GRN_PLUGINS_DIR");
- if (!plugins_dir) {
- plugins_dir = default_plugins_dir();
- }
- strcpy(path, plugins_dir);
+ if (name[0] == '/') {
+ path[0] = '\0';
+ } else {
+ plugins_dir = getenv("GRN_PLUGINS_DIR");
+ if (!plugins_dir) {
+ plugins_dir = default_plugins_dir();
+ }
+ strcpy(path, plugins_dir);
- dir_last_char = plugins_dir[strlen(path) - 1];
- if (dir_last_char != '/') {
- strcat(path, "/");
+ dir_last_char = plugins_dir[strlen(path) - 1];
+ if (dir_last_char != '/') {
+ strcat(path, "/");
+ }
}
name_length = strlen(name);
Modified: test/unit/core/test-plugin.c (+14 -0)
===================================================================
--- test/unit/core/test-plugin.c 2011-05-15 14:47:48 +0000 (a428312)
+++ test/unit/core/test-plugin.c 2011-05-15 14:50:28 +0000 (54c7eab)
@@ -25,6 +25,7 @@
void test_register_function(void);
void test_register_with_too_long_name(void);
+void test_register_by_absolute_path(void);
static gchar *tmp_directory, *plugins_dir, *plugins_dir_env;
@@ -164,3 +165,16 @@ test_register_too_long_name(void)
full_path),
cut_take_printf("register %s", long_name->str));
}
+
+void
+test_register_by_absolute_path(void)
+{
+ assert_send_command(cut_take_printf("register %s/string", plugins_dir));
+ assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
+ assert_send_command("load '[[\"_key\"],[\"groonga.org\"]]' Sites");
+ cut_assert_equal_string("[[[1],[[\"_score\",\"Int32\"]],[11]]]",
+ send_command("select Sites "
+ "--output_columns _score "
+ "--filter true "
+ "--scorer '_score=str_len(_key)'"));
+}