MCPcopy Create free account
hub / github.com/containerd/nerdctl / Cp

Function Cp

pkg/cmd/container/cp_linux.go:31–61  ·  view source on GitHub ↗

Cp copies files/folders between a running container and the local filesystem.

(ctx context.Context, client *containerd.Client, options types.ContainerCpOptions)

Source from the content-addressed store, hash-verified

29
30// Cp copies files/folders between a running container and the local filesystem.
31func Cp(ctx context.Context, client *containerd.Client, options types.ContainerCpOptions) error {
32 walker := &containerwalker.ContainerWalker{
33 Client: client,
34 OnFound: func(ctx context.Context, found containerwalker.Found) error {
35 if found.MatchCount > 1 {
36 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
37 }
38 return containerutil.CopyFiles(
39 ctx,
40 client,
41 found.Container,
42 options)
43 },
44 }
45 count, err := walker.Walk(ctx, options.ContainerReq)
46
47 if count == -1 {
48 if err == nil {
49 panic("nil error and count == -1 from ContainerWalker.Walk should never happen")
50 }
51 err = fmt.Errorf("unable to copy: %w", err)
52 } else if count == 0 {
53 if err != nil {
54 err = fmt.Errorf("unable to retrieve containers with error: %w", err)
55 } else {
56 err = fmt.Errorf("no container found for: %s", options.ContainerReq)
57 }
58 }
59
60 return err
61}

Callers 1

copyActionFunction · 0.92

Calls 2

WalkMethod · 0.95
CopyFilesFunction · 0.92

Tested by

no test coverage detected