From 89e143e91debe809155be867318cd1e7d0413c87 Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Thu, 17 Aug 2017 17:36:16 -0700 Subject: [PATCH] common/libkvs: Remove jansson_dirent Remove jansson_dirent internal library, as it is no longer used. Remove lingering includes of jansson_dirent.h. --- src/common/libkvs/Makefile.am | 7 -- src/common/libkvs/jansson_dirent.c | 131 ------------------------ src/common/libkvs/jansson_dirent.h | 48 --------- src/common/libkvs/kvs_commit.c | 2 - src/common/libkvs/test/jansson_dirent.c | 85 --------------- 5 files changed, 273 deletions(-) delete mode 100644 src/common/libkvs/jansson_dirent.c delete mode 100644 src/common/libkvs/jansson_dirent.h delete mode 100644 src/common/libkvs/test/jansson_dirent.c diff --git a/src/common/libkvs/Makefile.am b/src/common/libkvs/Makefile.am index 7150a5ef6b70..cf276729da58 100644 --- a/src/common/libkvs/Makefile.am +++ b/src/common/libkvs/Makefile.am @@ -17,8 +17,6 @@ libkvs_la_SOURCES = \ kvs_dir.c \ kvs_classic.c \ kvs_watch.c \ - jansson_dirent.c \ - jansson_dirent.h \ kvs_commit.c \ kvs_txn.c \ kvs_txn_private.h \ @@ -35,7 +33,6 @@ fluxcoreinclude_HEADERS = \ kvs_commit.h TESTS = \ - test_jansson_dirent.t \ test_kvs_txn.t \ test_kvs_lookup.t \ test_kvs_dir.t \ @@ -59,10 +56,6 @@ test_cppflags = \ $(AM_CPPFLAGS) \ -I$(top_srcdir)/src/common/libtap -test_jansson_dirent_t_SOURCES = test/jansson_dirent.c -test_jansson_dirent_t_CPPFLAGS = $(test_cppflags) -test_jansson_dirent_t_LDADD = $(test_ldadd) - test_kvs_txn_t_SOURCES = test/kvs_txn.c test_kvs_txn_t_CPPFLAGS = $(test_cppflags) test_kvs_txn_t_LDADD = $(test_ldadd) $(LIBDL) diff --git a/src/common/libkvs/jansson_dirent.c b/src/common/libkvs/jansson_dirent.c deleted file mode 100644 index 20aa2917a360..000000000000 --- a/src/common/libkvs/jansson_dirent.c +++ /dev/null @@ -1,131 +0,0 @@ -/*****************************************************************************\ - * Copyright (c) 2014 Lawrence Livermore National Security, LLC. Produced at - * the Lawrence Livermore National Laboratory (cf, AUTHORS, DISCLAIMER.LLNS). - * LLNL-CODE-658032 All rights reserved. - * - * This file is part of the Flux resource manager framework. - * For details, see https://github.com/flux-framework. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the license, or (at your option) - * any later version. - * - * Flux is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the terms and conditions of the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - * See also: http://www.gnu.org/licenses/ -\*****************************************************************************/ - -#if HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include -#include - -#include "src/common/libutil/blobref.h" - -#include "jansson_dirent.h" - -json_t *j_dirent_create (const char *type, void *arg) -{ - json_t *dirent = NULL; - bool valid_type = false; - - if (!(dirent = json_object ())) { - errno = ENOMEM; - goto error; - } - - if (!strcmp (type, "FILEREF") || !strcmp (type, "DIRREF")) { - char *ref = arg; - json_t *o; - - if (!(o = json_string (ref))) { - errno = ENOMEM; - goto error; - } - if (json_object_set_new (dirent, type, o) < 0) { - json_decref (o); - errno = ENOMEM; - goto error; - } - - valid_type = true; - } else if (!strcmp (type, "FILEVAL") || !strcmp (type, "DIRVAL") - || !strcmp (type, "LINKVAL")) { - json_t *val = arg; - - if (val) - json_incref (val); - else { - if (!(val = json_object ())) { - errno = ENOMEM; - goto error; - } - } - if (json_object_set_new (dirent, type, val) < 0) { - json_decref (val); - errno = ENOMEM; - goto error; - } - valid_type = true; - } - assert (valid_type == true); - - return dirent; - -error: - json_decref (dirent); - return NULL; -} - -int j_dirent_validate (json_t *dirent) -{ - json_t *o; - - if (!dirent) - goto error; - if ((o = json_object_get (dirent, "DIRVAL"))) { - const char *key; - json_t *val; - json_object_foreach (o, key, val) { - if (j_dirent_validate (val) < 0) - goto error; - } - } - else if ((o = json_object_get (dirent, "FILEVAL"))) { - if (json_typeof (o) == JSON_NULL) - goto error; - } - else if ((o = json_object_get (dirent, "LINKVAL"))) { - if (json_typeof (o) != JSON_STRING) - goto error; - } - else if ((o = json_object_get (dirent, "DIRREF")) - || (o = json_object_get (dirent, "FILEREF"))) { - if (json_typeof (o) != JSON_STRING) - goto error; - const char *s = json_string_value (o); - uint8_t hash[BLOBREF_MAX_DIGEST_SIZE]; - if (blobref_strtohash (s, hash, sizeof (hash)) < 0) - goto error; - } - else - goto error; - return 0; -error: - errno = EINVAL; - return -1; -} - -/* - * vi:tabstop=4 shiftwidth=4 expandtab - */ diff --git a/src/common/libkvs/jansson_dirent.h b/src/common/libkvs/jansson_dirent.h deleted file mode 100644 index c2be15a68b77..000000000000 --- a/src/common/libkvs/jansson_dirent.h +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include - -/* JSON directory object: - * list of key-value pairs where key is a name, value is a dirent - * - * JSON dirent objects: - * object containing one key-value pair where key is one of - * "FILEREF", "DIRREF", "FILEVAL", "DIRVAL", "LINKVAL", and value is a - * blobref key into ctx->store (FILEREF, DIRREF), an actual directory, file - * (value), or link target JSON object (FILEVAL, DIRVAL, LINKVAL). - * - * For example, consider KVS containing: - * a="foo" - * b="bar" - * c.d="baz" - * X -> c.d - * - * Root directory: - * {"a":{"FILEREF":"f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"}, - * "b":{"FILEREF","8714e0ef31edb00e33683f575274379955b3526c"}, - * "c":{"DIRREF","6eadd3a778e410597c85d74c287a57ad66071a45"}, - * "X":{"LINKVAL","c.d"}} - * - * Deep copy of root directory: - * {"a":{"FILEVAL":"foo"}, - * "b":{"FILEVAL","bar"}, - * "c":{"DIRVAL",{"d":{"FILEVAL":"baz"}}}, - * "X":{"LINKVAL","c.d"}} - * - * On LINKVAL's: - * - target is always fully qualified key name - * - links are always followed in path traversal of intermediate directories - * - for kvs_get, terminal links are only followed if 'readlink' flag is set - * - for kvs_put, terminal links are never followed - */ - -/* Create a KVS dirent. - * 'type' is one of { "FILEREF", "DIRREF", "FILEVAL", "DIRVAL", "LINKVAL" }. - * 'arg' is dependent on the type. This function asserts on failure. - */ -json_t *j_dirent_create (const char *type, void *arg); - -int j_dirent_validate (json_t *dirent); - -/* - * vi:tabstop=4 shiftwidth=4 expandtab - */ diff --git a/src/common/libkvs/kvs_commit.c b/src/common/libkvs/kvs_commit.c index 1981e2298ef9..818d9b846fa8 100644 --- a/src/common/libkvs/kvs_commit.c +++ b/src/common/libkvs/kvs_commit.c @@ -29,8 +29,6 @@ #include #include -#include "jansson_dirent.h" - #include "kvs_txn_private.h" #include "src/common/libutil/blobref.h" diff --git a/src/common/libkvs/test/jansson_dirent.c b/src/common/libkvs/test/jansson_dirent.c deleted file mode 100644 index 0b0a6676ce73..000000000000 --- a/src/common/libkvs/test/jansson_dirent.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -#include "src/common/libkvs/jansson_dirent.h" -#include "src/common/libtap/tap.h" - -void jdiag (json_t *o) -{ - if (o) { - char *tmp = json_dumps (o, JSON_COMPACT); - diag ("%s", tmp); - free (tmp); - } else - diag ("nil"); -} - -int main (int argc, char *argv[]) -{ - json_t *d1; - json_t *d2; - json_t *dir; - char *s; - - plan (NO_PLAN); - - d1 = j_dirent_create ("FILEREF", "sha1-fbedb4eb241948f6f802bf47d95ec932e9d4deaf"); - d2 = j_dirent_create ("FILEREF", "sha1-fbedb4eb241948f6f802bf47d95ec932e9d4deaf"); - ok (d1 && d2, - "j_dirent_create FILEREF works"); - jdiag (d1); - jdiag (d2); - ok (json_equal (d1, d2), - "json_equal says identical dirents match"); - ok (j_dirent_validate (d1) == 0 && j_dirent_validate (d2) == 0, - "j_dirent_validate says they are valid"); - json_decref (d1); - json_decref (d2); - - /* ownership of new objects transferred to dirents */ - d1 = j_dirent_create ("FILEVAL", json_integer (42)); - d2 = j_dirent_create ("FILEVAL", json_string ("hello world")); - ok (d1 && d2, - "j_dirent_create FILEVAL works"); - jdiag (d1); - jdiag (d2); - ok (json_equal (d1, d2) == false, - "json_equal says different dirents are different"); - ok (j_dirent_validate (d1) == 0 && j_dirent_validate (d2) == 0, - "j_dirent_validate says they are valid"); - json_decref (d1); - json_decref (d2); - - dir = json_object (); - json_object_set_new (dir, "foo", j_dirent_create ("FILEVAL", json_integer (33))); - json_object_set_new (dir, "bar", j_dirent_create ("FILEVAL", json_string ("Mrrrrnn?"))); - d1 = j_dirent_create ("DIRVAL", dir); - ok (d1 != NULL, - "j_dirent_create DIRVAL works"); - ok (j_dirent_validate (d1) == 0, - "j_dirent_validate says it is valid"); - jdiag (d1); - json_decref (d1); - - /* jansson: How is "null" decoded? How is NULL encoded? */ - json_t *o; - char *str; - o = json_loads ("null", JSON_DECODE_ANY, NULL); - ok (o != NULL, - "json_loads (\"null\") decodes as valid json_t"); - str = json_dumps (o, JSON_ENCODE_ANY); - ok (str != NULL && !strcmp (str, "null"), - "json_dumps encodes returned object as \"null\""); - free (str); - json_decref (o); - s = json_dumps (NULL, JSON_ENCODE_ANY); - ok (s == NULL, - "json_dumps (NULL) returns NULL, which is a failure"); - - done_testing(); - return (0); -} - -/* - * vi:tabstop=4 shiftwidth=4 expandtab - */