diff --git a/src/cmd/flux-kvs.c b/src/cmd/flux-kvs.c index 166beb209ef3..0bce05b29d4f 100644 --- a/src/cmd/flux-kvs.c +++ b/src/cmd/flux-kvs.c @@ -67,6 +67,7 @@ void cmd_dirsize (flux_t h, int argc, char **argv); void cmd_get_treeobj (flux_t h, int argc, char **argv); void cmd_put_treeobj (flux_t h, int argc, char **argv); void cmd_getat (flux_t h, int argc, char **argv); +void cmd_dirat (flux_t h, int argc, char **argv); void usage (void) @@ -95,6 +96,7 @@ void usage (void) " flux-kvs get-treeobj key\n" " flux-kvs put-treeobj key=treeobj\n" " flux-kvs getat treeobj key\n" +" flux-kvs dirat [-r] treeobj [key]\n" ); exit (1); } @@ -170,6 +172,8 @@ int main (int argc, char *argv[]) cmd_put_treeobj (h, argc - optind, argv + optind); else if (!strcmp (cmd, "getat")) cmd_getat (h, argc - optind, argv + optind); + else if (!strcmp (cmd, "dirat")) + cmd_dirat (h, argc - optind, argv + optind); else usage (); @@ -609,6 +613,63 @@ void cmd_dir (flux_t h, int argc, char **argv) log_msg_exit ("dir: specify zero or one directory"); } +static void dump_kvs_dirat (flux_t h, bool ropt, + const char *treeobj, const char *path) +{ + kvsdir_t *dir; + kvsitr_t *itr; + const char *name; + char *key; + + if (kvs_get_dirat (h, treeobj, path, &dir) < 0) + log_err_exit ("%s", path); + + itr = kvsitr_create (dir); + while ((name = kvsitr_next (itr))) { + key = kvsdir_key_at (dir, name); + if (kvsdir_issymlink (dir, name)) { + char *link; + if (kvs_get_symlinkat (h, treeobj, key, &link) < 0) + log_err_exit ("%s", key); + printf ("%s -> %s\n", key, link); + free (link); + + } else if (kvsdir_isdir (dir, name)) { + if (ropt) + dump_kvs_dirat (h, ropt, treeobj, key); + else + printf ("%s.\n", key); + } else { + char *json_str; + if (kvs_getat (h, treeobj, key, &json_str) < 0) + log_err_exit ("%s", key); + dump_kvs_val (key, json_str); + free (json_str); + } + free (key); + } + kvsitr_destroy (itr); + kvsdir_destroy (dir); + +} + +void cmd_dirat (flux_t h, int argc, char **argv) +{ + bool ropt = false; + + if (argc > 0 && !strcmp (argv[0], "-r")) { + ropt = true; + argc--; + argv++; + } + if (argc == 1) + dump_kvs_dirat (h, ropt, argv[0], "."); + else if (argc == 2) + dump_kvs_dirat (h, ropt, argv[0], argv[1]); + else + log_msg_exit ("dirat: specify treeobj and zero or one directory"); +} + void cmd_dirsize (flux_t h, int argc, char **argv) { kvsdir_t *dir = NULL;