Kouhei Sutou
null+****@clear*****
Wed Jan 13 16:27:21 JST 2016
Kouhei Sutou 2016-01-13 16:27:21 +0900 (Wed, 13 Jan 2016) New Revision: f8042510ae069373107447d63ed519110f4d3e60 https://github.com/groonga/groonga/commit/f8042510ae069373107447d63ed519110f4d3e60 Message: Add grn_conf_delete() Modified files: include/groonga/conf.h lib/conf.c test/unit/core/test-conf.c Modified: include/groonga/conf.h (+2 -0) =================================================================== --- include/groonga/conf.h 2016-01-13 15:59:00 +0900 (d9e975c) +++ include/groonga/conf.h 2016-01-13 16:27:21 +0900 (c49cc83) @@ -33,6 +33,8 @@ GRN_API grn_rc grn_conf_set(grn_ctx *ctx, GRN_API grn_rc grn_conf_get(grn_ctx *ctx, const char *key, int key_size, const char **value, uint32_t *value_size); +GRN_API grn_rc grn_conf_delete(grn_ctx *ctx, + const char *key, int key_size); #ifdef __cplusplus } Modified: lib/conf.c (+47 -1) =================================================================== --- lib/conf.c 2016-01-13 15:59:00 +0900 (2dc1c61) +++ lib/conf.c 2016-01-13 16:27:21 +0900 (e8432e0) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2 -*- */ /* - Copyright(C) 2015 Brazil + Copyright(C) 2015-2016 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -125,3 +125,49 @@ grn_conf_get(grn_ctx *ctx, *value_size = *((uint32_t *)packed_value); GRN_API_RETURN(GRN_SUCCESS); } + +grn_rc +grn_conf_delete(grn_ctx *ctx, + const char *key, int key_size) +{ + grn_obj *db; + grn_hash *conf; + + GRN_API_ENTER; + + if (!ctx || !ctx->impl || !(db = ctx->impl->db)) { + ERR(GRN_INVALID_ARGUMENT, "[conf][delete] DB isn't initialized"); + GRN_API_RETURN(ctx->rc); + } + + if (key_size == -1) { + key_size = strlen(key); + } + if (key_size > GRN_CONF_MAX_KEY_SIZE) { + ERR(GRN_INVALID_ARGUMENT, + "[conf][delete] too large key: max=<%d>: <%d>", + GRN_CONF_MAX_KEY_SIZE, key_size); + GRN_API_RETURN(ctx->rc); + } + + conf = ((grn_db *)db)->conf; + { + grn_rc rc; + rc = grn_io_lock(ctx, conf->io, grn_lock_timeout); + if (rc != GRN_SUCCESS) { + if (ctx->rc == GRN_SUCCESS) { + ERR(rc, "[conf][delete] failed to lock"); + } + GRN_API_RETURN(rc); + } + rc = grn_hash_delete(ctx, conf, key, key_size, NULL); + grn_io_unlock(conf->io); + if (rc != GRN_SUCCESS) { + if (ctx->rc == GRN_SUCCESS) { + ERR(rc, "[conf][delete] failed to delete"); + } + } + } + + GRN_API_RETURN(ctx->rc); +} Modified: test/unit/core/test-conf.c (+18 -1) =================================================================== --- test/unit/core/test-conf.c 2016-01-13 15:59:00 +0900 (2df0301) +++ test/unit/core/test-conf.c 2016-01-13 16:27:21 +0900 (43bf0d6) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2; coding: utf-8 -*- */ /* - Copyright (C) 2015 Kouhei Sutou <kou �� clear-code.com> + Copyright (C) 2015-2016 Kouhei Sutou <kou �� clear-code.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -30,6 +30,7 @@ static grn_obj *database; void test_set_and_get(void); void test_get_nonexistent(void); +void test_delete(void); void cut_startup(void) @@ -91,3 +92,19 @@ test_get_nonexistent(void) value, value_size); } +void +test_delete(void) +{ + const char *value; + uint32_t value_size; + + grn_test_assert(grn_conf_set(&context, "key", -1, "value", -1)); + grn_test_assert(grn_conf_get(&context, "key", -1, &value, &value_size)); + cut_assert_equal_memory("value", strlen("value"), + value, value_size); + + grn_test_assert(grn_conf_delete(&context, "key", -1)); + grn_test_assert(grn_conf_get(&context, "key", -1, &value, &value_size)); + cut_assert_equal_memory(NULL, 0, + value, value_size); +} -------------- next part -------------- HTML����������������������������...Download