Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial flux-kvs cleanup #928

Merged
merged 27 commits into from Dec 22, 2016
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fba3707
test/basic: Add new program for kvs testing
chu11 Dec 1, 2016
6050caf
test/kvs: Adjust kvs basic tests
chu11 Dec 1, 2016
4f105c7
test/kvs: Remove kvs dir -d tests
chu11 Dec 2, 2016
b392174
test/kvs: Remove multi-input in basic tests
chu11 Dec 2, 2016
8dc8aad
test/kvs: Remove user 'convenience' input
chu11 Dec 2, 2016
ca999cc
cmd/flux-kvs: Remove legacy debugging
chu11 Dec 12, 2016
964374c
cmd/flux-kvs: Remove commands
chu11 Dec 9, 2016
0b9f100
doc/flux-kvs(1): Remove deleted commands
chu11 Dec 9, 2016
775c039
cmd/flux-kvs: Alter watch and watchdir logic
chu11 Dec 9, 2016
28acc69
cmd/flux-kvs: Add -o option to watch and watchdir
chu11 Dec 9, 2016
640eddd
doc/flux-kvs(1): Update watch/watch-dir commands
chu11 Dec 12, 2016
ea27fa3
cmd/flux-kvs: Refactor to use liboptparse
chu11 Dec 12, 2016
2db49f0
doc/flux-kvs(1): Update multi-input documentation
chu11 Dec 14, 2016
529729d
cmd/flux-kvs(1): Change -r to -R
chu11 Dec 14, 2016
dfa7686
doc/flux-kvs(1): Change -r to -R
chu11 Dec 14, 2016
b7c2979
cmd/flux-kvs: Make 'count' an option
chu11 Dec 14, 2016
2d2e9d9
doc/flux-kvs(1): Document new -c option
chu11 Dec 14, 2016
331d309
cmd/flux-kvs: Merge dropcache commands
chu11 Dec 14, 2016
834ae7f
doc/flux-kvs(1): Update dropcache usage
chu11 Dec 14, 2016
39f44f9
cmd/flux-kvs(1): Handle errors in unlink
chu11 Dec 15, 2016
c3d6758
doc/flux-kvs(1): Update new unlink usage
chu11 Dec 15, 2016
b8747dc
cmd/flux-kvs: Merge watch and watch-dir
chu11 Dec 16, 2016
c3ea83d
doc/flux-kvs(1): Document new watch command usage
chu11 Dec 17, 2016
cf97442
test: Update tests for new flux-kvs usage
chu11 Dec 17, 2016
f195227
test/kvs: Fix error in kvs basic tests
chu11 Dec 20, 2016
f065894
test/kvs-cmd: Add flux-kvs tool tests
chu11 Dec 19, 2016
0702878
doc/flux-kvs(1): Minor re-organizing
chu11 Dec 22, 2016
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+40 −4
Diff settings

Always

Just for now

cmd/flux-kvs(1): Handle errors in unlink

Handle error situations in unlink subcommand, such as when user
attempts to remove non-existent KVS entries or non-empty directories.
Support -R option to unlink to recursively delete non-empty directories.
  • Loading branch information...
chu11 committed Dec 15, 2016
commit 39f44f9d377fc308a2abf0414f1e29f81427e54a
Copy path View file
@@ -94,6 +94,13 @@ static struct optparse_option dropcache_opts[] = {
OPTPARSE_TABLE_END
};

static struct optparse_option unlink_opts[] = {
{ .name = "recursive", .key = 'R', .has_arg = 0,
.usage = "Remove directory contents recursively",
},
OPTPARSE_TABLE_END
};

static struct optparse_subcommand subcommands[] = {
{ "get",
"key [key...]",
@@ -121,7 +128,7 @@ static struct optparse_subcommand subcommands[] = {
"Remove key",
cmd_unlink,
0,
NULL
unlink_opts
},
{ "link",
"target linkname",
@@ -359,10 +366,32 @@ int cmd_put (optparse_t *p, int argc, char **argv)
return (0);
}

bool key_exists (flux_t *h, const char *key, bool *isdir, int *dirsize)
{
char *json_str = NULL;
kvsdir_t *dir = NULL;

if (kvs_get (h, key, &json_str) == 0) {
*isdir = false;
free (json_str);
return true;
}
if (errno == EISDIR && kvs_get_dir (h, &dir, "%s", key) == 0) {
*dirsize = kvsdir_get_size (dir);
*isdir = true;
kvsdir_destroy (dir);
return true;
}
*isdir = false;
return false;
}

int cmd_unlink (optparse_t *p, int argc, char **argv)
{
flux_t *h;
int optindex, i;
int optindex, dirsize, i;
bool Ropt;
bool isdir;

h = (flux_t *)optparse_get_data (p, "flux_handle");

@@ -372,9 +401,16 @@ int cmd_unlink (optparse_t *p, int argc, char **argv)
optparse_print_usage (p);
exit (1);
}

Ropt = optparse_hasopt (p, "recursive");

for (i = optindex; i < argc; i++) {
/* FIXME: unlink nonexistent silently fails */
/* FIXME: unlink directory silently succeeds */
if (!key_exists (h, argv[i], &isdir, &dirsize))
log_msg_exit ("cannot unlink '%s': %s",
argv[i], strerror (ENOENT));
if (isdir && !Ropt && dirsize > 0)
log_msg_exit ("cannot unlink '%s': %s",
argv[i], strerror (ENOTEMPTY));
if (kvs_unlink (h, argv[i]) < 0)
log_err_exit ("%s", argv[i]);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.