Cp copies files/folders between a running container and the local filesystem.
(ctx context.Context, client *containerd.Client, options types.ContainerCpOptions)
| 29 | |
| 30 | // Cp copies files/folders between a running container and the local filesystem. |
| 31 | func 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 | } |
no test coverage detected