(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig)
| 255 | } |
| 256 | |
| 257 | func copyFromContainer(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig) (err error) { |
| 258 | dstPath := copyConfig.destPath |
| 259 | srcPath := copyConfig.sourcePath |
| 260 | |
| 261 | if dstPath != "-" { |
| 262 | // Get an absolute destination path. |
| 263 | dstPath, err = resolveLocalPath(dstPath) |
| 264 | if err != nil { |
| 265 | return err |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | if err := command.ValidateOutputPath(dstPath); err != nil { |
| 270 | return err |
| 271 | } |
| 272 | |
| 273 | apiClient := dockerCLI.Client() |
| 274 | // if client requests to follow symlinks, then must decide target file to be copied |
| 275 | var rebaseName string |
| 276 | if copyConfig.followLink { |
| 277 | src, err := apiClient.ContainerStatPath(ctx, copyConfig.container, client.ContainerStatPathOptions{ |
| 278 | Path: srcPath, |
| 279 | }) |
| 280 | |
| 281 | // If the destination is a symbolic link, we should follow it. |
| 282 | if err == nil && src.Stat.Mode&os.ModeSymlink != 0 { |
| 283 | linkTarget := src.Stat.LinkTarget |
| 284 | if !isAbs(linkTarget) { |
| 285 | // Join with the parent directory. |
| 286 | srcParent, _ := archive.SplitPathDirEntry(srcPath) |
| 287 | linkTarget = filepath.Join(srcParent, linkTarget) |
| 288 | } |
| 289 | |
| 290 | linkTarget, rebaseName = archive.GetRebaseName(srcPath, linkTarget) |
| 291 | srcPath = linkTarget |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | ctx, cancel := signal.NotifyContext(ctx, os.Interrupt) |
| 296 | defer cancel() |
| 297 | |
| 298 | cpRes, err := apiClient.CopyFromContainer(ctx, copyConfig.container, client.CopyFromContainerOptions{ |
| 299 | SourcePath: srcPath, |
| 300 | }) |
| 301 | if err != nil { |
| 302 | return err |
| 303 | } |
| 304 | content := cpRes.Content |
| 305 | defer func() { _ = content.Close() }() |
| 306 | |
| 307 | if dstPath == "-" { |
| 308 | _, err = io.Copy(dockerCLI.Out(), content) |
| 309 | return err |
| 310 | } |
| 311 | |
| 312 | srcInfo := archive.CopyInfo{ |
| 313 | Path: srcPath, |
| 314 | Exists: true, |
no test coverage detected
searching dependent graphs…