Skip to content

Commit

Permalink
cmd/flux-kvs: Add put --append option
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Oct 31, 2017
1 parent fa41127 commit 2dec83b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions doc/man1/flux-kvs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ interpreted as encoded JSON and formatted accordingly. If '-r', value
is displayed without a newline. If '-t', the RFC 11 object is displayed.
'-a treeobj' causes the lookup to be relative to an RFC 11 snapshot reference.

*put* [-j|-r|-t] [-n] 'key=value' ['key=value...']::
*put* [-j|-r|-t] [-n] [-A] 'key=value' ['key=value...']::
Store 'value' under 'key' and commit it. If it already has a value,
overwrite it. If no options, value is stored directly. If '-j', it is
first encoded as JSON, then stored. If '-r', the value may be read from
standard input if specified as "-", and may include embedded NULL bytes.
If '-t', value is stored as a RFC 11 object. '-n' prevents the commit
from being merged with with other contemporaneous commits.
from being merged with with other contemporaneous commits. '-A' appends the
value to a key instead of overwriting the value. Append is incompatible with
the -j option.

*ls* [-R] [-d] [-F] [-w COLS] [-1] ['key' ...]::
Display directory referred to by _key_, or "." (root) if unspecified.
Expand Down
15 changes: 13 additions & 2 deletions src/cmd/flux-kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ static struct optparse_option put_opts[] = {
{ .name = "no-merge", .key = 'n', .has_arg = 0,
.usage = "Set the NO_MERGE flag to ensure commit is standalone",
},
{ .name = "append", .key = 'A', .has_arg = 0,
.usage = "Append value(s) to key instead of overwriting",
},
OPTPARSE_TABLE_END
};

Expand Down Expand Up @@ -498,6 +501,7 @@ int cmd_put (optparse_t *p, int argc, char **argv)
flux_future_t *f;
flux_kvs_txn_t *txn;
int commit_flags = 0;
int put_flags = 0;

optindex = optparse_option_index (p);
if ((optindex - argc) == 0) {
Expand Down Expand Up @@ -534,18 +538,25 @@ int cmd_put (optparse_t *p, int argc, char **argv)
else if (optparse_hasopt (p, "raw")) {
int len;
uint8_t *buf = NULL;

if (optparse_hasopt (p, "append"))
put_flags |= FLUX_KVS_APPEND;

if (!strcmp (val, "-")) { // special handling for "--raw key=-"
if ((len = read_all (STDIN_FILENO, &buf)) < 0)
log_err_exit ("stdin");
val = (char *)buf;
} else
len = strlen (val);
if (flux_kvs_txn_put_raw (txn, 0, key, val, len) < 0)
if (flux_kvs_txn_put_raw (txn, put_flags, key, val, len) < 0)
log_err_exit ("%s", key);
free (buf);
}
else {
if (flux_kvs_txn_put (txn, 0, key, val) < 0)
if (optparse_hasopt (p, "append"))
put_flags |= FLUX_KVS_APPEND;

if (flux_kvs_txn_put (txn, put_flags, key, val) < 0)
log_err_exit ("%s", key);
}
free (key);
Expand Down

0 comments on commit 2dec83b

Please sign in to comment.