1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package abi
import (
"context"
"github.com/containers/podman/v2/libpod"
"github.com/containers/podman/v2/pkg/copy"
"github.com/containers/podman/v2/pkg/domain/entities"
)
func (ic *ContainerEngine) ContainerCp(ctx context.Context, source, dest string, options entities.ContainerCpOptions) error {
// Parse user input.
sourceContainerStr, sourcePath, destContainerStr, destPath, err := copy.ParseSourceAndDestination(source, dest)
if err != nil {
return err
}
// Look up containers.
var sourceContainer, destContainer *libpod.Container
if len(sourceContainerStr) > 0 {
sourceContainer, err = ic.Libpod.LookupContainer(sourceContainerStr)
if err != nil {
return err
}
}
if len(destContainerStr) > 0 {
destContainer, err = ic.Libpod.LookupContainer(destContainerStr)
if err != nil {
return err
}
}
var sourceItem, destinationItem copy.CopyItem
// Source ... container OR host.
if sourceContainer != nil {
sourceItem, err = copy.CopyItemForContainer(sourceContainer, sourcePath, options.Pause, true)
defer sourceItem.CleanUp()
if err != nil {
return err
}
} else {
sourceItem, err = copy.CopyItemForHost(sourcePath, true)
if err != nil {
return err
}
}
// Destination ... container OR host.
if destContainer != nil {
destinationItem, err = copy.CopyItemForContainer(destContainer, destPath, options.Pause, false)
defer destinationItem.CleanUp()
if err != nil {
return err
}
} else {
destinationItem, err = copy.CopyItemForHost(destPath, false)
defer destinationItem.CleanUp()
if err != nil {
return err
}
}
// Copy from the host to the container.
copier, err := copy.GetCopier(&sourceItem, &destinationItem, options.Extract)
if err != nil {
return err
}
return copier.Copy()
}
|