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

Add error message when container is exist when nerdctl cp #3275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
8 changes: 7 additions & 1 deletion pkg/cmd/container/cp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import (

// Cp copies files/folders between a running container and the local filesystem.
func Cp(ctx context.Context, client *containerd.Client, options types.ContainerCpOptions) error {
foundMatchCount := 0
walker := &containerwalker.ContainerWalker{
Client: client,
OnFound: func(ctx context.Context, found containerwalker.Found) error {
foundMatchCount = found.MatchCount
if found.MatchCount > 1 {
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
}
Expand All @@ -48,7 +50,11 @@ func Cp(ctx context.Context, client *containerd.Client, options types.ContainerC
count, err := walker.Walk(ctx, options.ContainerReq)

if count < 1 {
err = fmt.Errorf("could not find container: %s, with error: %w", options.ContainerReq, err)
if foundMatchCount == 0 {
err = fmt.Errorf("could not find container: %s, with error: %w", options.ContainerReq, err)
} else {
err = fmt.Errorf("could not find %s in container %s", options.SrcPath, options.ContainerReq)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containerwalker.ContainerWalker is just searching for containers.

// Walk walks containers and calls w.OnFound .
// Req is name, short ID, or long ID.
// Returns the number of the found entries.

}
}

return err
Expand Down