rm: check early if deleting a directory without --recursive
This avoids an obsolete confirmation check (without --force), because the operation is not allowed anyway.
@@ -7,7 +7,6 @@ import (
"github.com/gopasspw/gopass/pkg/store/sub"
"github.com/gopasspw/gopass/pkg/termio"
- "github.com/pkg/errors"
"github.com/urfave/cli"
)
@@ -21,6 +20,10 @@ func (s *Action) Delete(ctx context.Context, c *cli.Context) error {
return ExitError(ctx, ExitUsage, nil, "Usage: %s rm name", s.Name)
}
+ if !recursive && s.Store.IsDir(ctx, name) {
+ return ExitError(ctx, ExitUsage, nil, "Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name)
+ }
+
// specifying a key is optional
key := c.Args().Get(1)
@@ -41,10 +44,6 @@ func (s *Action) Delete(ctx context.Context, c *cli.Context) error {
return nil
}
- if s.Store.IsDir(ctx, name) {
- return errors.Errorf("Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name)
- }
-
// deletes a single key from a YAML doc
if key != "" {
return s.deleteKeyFromYAML(ctx, name, key)
