MCPcopy Index your code
hub / github.com/docker/cli / copyFromContainer

Function copyFromContainer

cli/command/container/cp.go:257–349  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, copyConfig cpConfig)

Source from the content-addressed store, hash-verified

255}
256
257func 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,

Callers 1

runCopyFunction · 0.85

Calls 10

resolveLocalPathFunction · 0.85
copyProgressFunction · 0.85
copySummaryFunction · 0.85
ContainerStatPathMethod · 0.80
CopyFromContainerMethod · 0.80
isAbsFunction · 0.70
ClientMethod · 0.65
OutMethod · 0.65
ErrMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…