The provided input will be extracted into the container's containerPath directory
(containerID string, input *archive.Input, containerPath string)
| 249 | |
| 250 | // The provided input will be extracted into the container's containerPath directory |
| 251 | func CopyToContainer(containerID string, input *archive.Input, containerPath string) error { |
| 252 | if !strings.HasPrefix(containerPath, "/") { |
| 253 | return errors.ErrorUnexpected("containerPath must start with /") |
| 254 | } |
| 255 | |
| 256 | dockerClient, err := GetDockerClient() |
| 257 | if err != nil { |
| 258 | return err |
| 259 | } |
| 260 | |
| 261 | // this is necessary to ensure that missing parent directories are created in the container |
| 262 | input.AddPrefix = filepath.Join(containerPath, input.AddPrefix) |
| 263 | |
| 264 | buf := new(bytes.Buffer) |
| 265 | _, err = archive.TarToWriter(input, buf) |
| 266 | if err != nil { |
| 267 | return err |
| 268 | } |
| 269 | |
| 270 | err = dockerClient.CopyToContainer(context.Background(), containerID, "/", buf, dockertypes.CopyToContainerOptions{ |
| 271 | AllowOverwriteDirWithFile: true, |
| 272 | }) |
| 273 | if err != nil { |
| 274 | return WrapDockerError(err) |
| 275 | } |
| 276 | |
| 277 | return nil |
| 278 | } |
| 279 | |
| 280 | // The file or directory name of containerPath will be preserved in localDir |
| 281 | // For example, if the container has /aaa/zzz.txt, |
no test coverage detected