Skip to content

Commit

Permalink
Do not recurse when deleting a key (gopasspw#1907)
Browse files Browse the repository at this point in the history
Fixes gopasspw#1906

RELEASE_NOTES=[BUGFIX] Do not recurse with a key

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Apr 19, 2021
1 parent c058dbf commit b39457c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/action/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (s *Action) Delete(c *cli.Context) error {
// specifying a key is optional
key := c.Args().Get(1)

if recursive && key != "" {
return ExitError(ExitUsage, nil, "Can not use -r with a key. Invoke delete either with a key or with -r")
}

if !force { // don't check if it's force anyway
recStr := ""
if recursive {
Expand All @@ -39,7 +43,7 @@ func (s *Action) Delete(c *cli.Context) error {
}
}

if recursive {
if recursive && key == "" {
debug.Log("pruning %q", name)
if err := s.Store.Prune(ctx, name); err != nil {
return ExitError(ExitUnknown, err, "failed to prune %q: %s", name, err)
Expand Down
5 changes: 5 additions & 0 deletions internal/action/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ func TestDelete(t *testing.T) {
c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"recursive": "true"}, "foo")
assert.NoError(t, act.Delete(c))
buf.Reset()

// reject recursive flag when a key is given
c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"recursive": "true"}, "foo", "bar")
assert.Error(t, act.Delete(c))
buf.Reset()
}

0 comments on commit b39457c

Please sign in to comment.