mirror of
https://github.com/gopasspw/gopass.git
synced 2026-02-01 17:37:29 +00:00
[BUGFIX] Allow to move shadowed entries into their own folder (#2718)
Fixes #892 Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
This commit is contained in:
parent
7dca311fcc
commit
ccd748e93f
@ -42,14 +42,7 @@ func (r *Store) move(ctx context.Context, from, to string, del bool) error {
|
||||
subFrom, fromPrefix := r.getStore(from)
|
||||
subTo, _ := r.getStore(to)
|
||||
|
||||
srcIsDir := r.IsDir(ctx, from)
|
||||
dstIsDir := r.IsDir(ctx, to)
|
||||
|
||||
if srcIsDir && r.Exists(ctx, to) && !dstIsDir {
|
||||
return fmt.Errorf("destination is a file")
|
||||
}
|
||||
|
||||
if err := r.moveFromTo(ctx, subFrom, from, to, fromPrefix, srcIsDir, dstIsDir, del); err != nil {
|
||||
if err := r.moveFromTo(ctx, subFrom, from, to, fromPrefix, del); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -124,13 +117,21 @@ func (r *Store) move(ctx context.Context, from, to string, del bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Store) moveFromTo(ctx context.Context, subFrom *leaf.Store, from, to, fromPrefix string, srcIsDir, dstIsDir, del bool) error {
|
||||
func (r *Store) moveFromTo(ctx context.Context, subFrom *leaf.Store, from, to, fromPrefix string, del bool) error {
|
||||
ctx = ctxutil.WithGitCommit(ctx, false)
|
||||
|
||||
// source is a directory and not a "shadowed" leaf
|
||||
srcIsDir := r.IsDir(ctx, from) && !r.Exists(ctx, from)
|
||||
dstIsDir := r.IsDir(ctx, to)
|
||||
|
||||
if srcIsDir && r.Exists(ctx, to) && !dstIsDir {
|
||||
return fmt.Errorf("destination is a file")
|
||||
}
|
||||
|
||||
entries := []string{from}
|
||||
// if the source is a directory we enumerate all it's children
|
||||
// and move them one by one.
|
||||
if r.IsDir(ctx, from) {
|
||||
if srcIsDir {
|
||||
var err error
|
||||
|
||||
entries, err = subFrom.List(ctx, fromPrefix+"/")
|
||||
|
||||
@ -416,3 +416,40 @@ func TestComputeMoveDestination(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegression892(t *testing.T) {
|
||||
u := gptest.NewUnitTester(t)
|
||||
u.Entries = []string{
|
||||
"some/example",
|
||||
"some/example/test2",
|
||||
"communication/t1",
|
||||
}
|
||||
require.NoError(t, u.InitStore(""))
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
||||
ctx = ctxutil.WithHidden(ctx, true)
|
||||
|
||||
rs, err := createRootStore(ctx, u)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, rs.Delete(ctx, "foo"))
|
||||
|
||||
// Initial state:
|
||||
entries, err := rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{
|
||||
"communication/t1",
|
||||
"some/example",
|
||||
"some/example/test2",
|
||||
}, entries)
|
||||
|
||||
// -> move comm email => Rename comm to email
|
||||
require.NoError(t, rs.Move(ctx, "some/example", "some/example/test1"))
|
||||
entries, err = rs.List(ctx, tree.INF)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{
|
||||
"communication/t1",
|
||||
"some/example/test1",
|
||||
"some/example/test2",
|
||||
}, entries)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user