Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Copy with trailing slash at destination. #2966

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/action/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import (
"context"
"fmt"
"path/filepath"
"strings"

"github.com/gopasspw/gopass/internal/action/exit"
"github.com/gopasspw/gopass/pkg/ctxutil"
Expand Down Expand Up @@ -30,6 +32,36 @@
return exit.Error(exit.NotFound, nil, "%s does not exist", from)
}

isSourceDir := s.Store.IsDir(ctx, from)
hasTrailingSlash := strings.HasSuffix(to, "/")

if isSourceDir && hasTrailingSlash {
return s.copyFlattenDir(ctx, from, to, force)
}

return s.copyRegular(ctx, from, to, force)
}

func (s *Action) copyFlattenDir(ctx context.Context, from, to string, force bool) error {
entries, err := s.Store.List(ctx, 0)
if err != nil {
return exit.Error(exit.List, err, "failed to list entries in %q", from)
}

for _, entry := range entries {
fromPath := filepath.Join(from, entry)
toPath := filepath.Join(to, filepath.Base(entry))

if err := s.copyRegular(ctx, fromPath, toPath, force); err != nil {
return err
}
}

return nil
}

func (s *Action) copyRegular(ctx context.Context, from, to string, force bool) error {

Check failure on line 63 in internal/action/copy.go

View workflow job for this annotation

GitHub Actions / linux

unnecessary leading newline (whitespace)

Check failure on line 63 in internal/action/copy.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return exit.Error(exit.Aborted, nil, "not overwriting your current secret")
Expand Down
Loading