(ctx context.Context, containerID, srcPath, dstPath string, opts api.CopyOptions)
| 254 | } |
| 255 | |
| 256 | func (s *composeService) copyFromContainer(ctx context.Context, containerID, srcPath, dstPath string, opts api.CopyOptions) error { |
| 257 | var err error |
| 258 | if dstPath != "-" { |
| 259 | // Get an absolute destination path. |
| 260 | dstPath, err = resolveLocalPath(dstPath) |
| 261 | if err != nil { |
| 262 | return err |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if err := command.ValidateOutputPath(dstPath); err != nil { |
| 267 | return err |
| 268 | } |
| 269 | |
| 270 | // if client requests to follow symbol link, then must decide target file to be copied |
| 271 | var rebaseName string |
| 272 | if opts.FollowLink { |
| 273 | var srcStat container.PathStat |
| 274 | res, err := s.apiClient().ContainerStatPath(ctx, containerID, client.ContainerStatPathOptions{ |
| 275 | Path: srcPath, |
| 276 | }) |
| 277 | if err == nil { |
| 278 | srcStat = res.Stat |
| 279 | } |
| 280 | |
| 281 | // If the destination is a symbolic link, we should follow it. |
| 282 | if err == nil && srcStat.Mode&os.ModeSymlink != 0 { |
| 283 | linkTarget := srcStat.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 | res, err := s.apiClient().CopyFromContainer(ctx, containerID, client.CopyFromContainerOptions{ |
| 296 | SourcePath: srcPath, |
| 297 | }) |
| 298 | if err != nil { |
| 299 | return err |
| 300 | } |
| 301 | defer res.Content.Close() //nolint:errcheck |
| 302 | |
| 303 | if dstPath == "-" { |
| 304 | _, err = io.Copy(s.stdout(), res.Content) |
| 305 | return err |
| 306 | } |
| 307 | |
| 308 | srcInfo := archive.CopyInfo{ |
| 309 | Path: srcPath, |
| 310 | Exists: true, |
| 311 | IsDir: res.Stat.Mode.IsDir(), |
| 312 | RebaseName: rebaseName, |
| 313 | } |
nothing calls this directly
no test coverage detected