Skip to content

Commit

Permalink
etcdctl/command: mk command with PrevNoExist
Browse files Browse the repository at this point in the history
This attempts to fix #3676. `PrevNoExist` checks if the key previously exists
and if so, it returns an error, which is how `mk` command is supposed to work.
The previous code ignores the previous key and overwrites with the later value.

/cc @yichengq
  • Loading branch information
gyuho authored and yichengq committed Oct 15, 2015
1 parent 71e5467 commit 45c86af
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion etcdctl/command/mk_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func mkCommandFunc(c *cli.Context, ki client.KeysAPI) {
ttl := c.Int("ttl")

ctx, cancel := contextWithTotalTimeout(c)
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevIgnore})
// Since PrevNoExist means that the Node must not exist previously,
// this Set method always creates a new key. Therefore, mk command
// succeeds only if the key did not previously exist, and the command
// prevents one from overwriting values accidentally.
resp, err := ki.Set(ctx, key, value, &client.SetOptions{TTL: time.Duration(ttl) * time.Second, PrevExist: client.PrevNoExist})
cancel()
if err != nil {
handleError(ExitServerError, err)
Expand Down

0 comments on commit 45c86af

Please sign in to comment.