-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_args.go
50 lines (42 loc) · 1.44 KB
/
copy_args.go
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
package sandbox
import (
"fmt"
"strings"
)
// copySpec specifies the source and destination of a copy operation.
// The copy may be made from the host into the sandbox or vice versa.
// See https://docs.podman.io/en/latest/markdown/podman-cp.1.html for
// semantics of src and dest paths.
// srcInContainer and destInContainer specify whether the copy source
// and destination are respectively in the host (false) or container (true)
type copySpec struct {
src string
dest string
srcInContainer bool
destInContainer bool
containerId string
}
func (c copySpec) Args() []string {
copySrc := c.src
if c.srcInContainer {
copySrc = fmt.Sprintf("%s:%s", c.containerId, c.src)
}
copyDest := c.dest
if c.destInContainer {
copyDest = fmt.Sprintf("%s:%s", c.containerId, c.dest)
}
return []string{"cp", copySrc, copyDest}
}
func (c copySpec) String() string {
return strings.Join(c.Args(), " ")
}
// hostToContainerCopyCmd generates the arguments to podman
// that copy a file from the host to the container.
func hostToContainerCopyCmd(hostPath, containerPath, containerId string) copySpec {
return copySpec{hostPath, containerPath, false, true, containerId}
}
// hostToContainerCopyCmd generates the arguments to podman
// that copy a file from the container to host.
func containerToHostCopyCmd(hostPath, containerPath, containerId string) copySpec {
return copySpec{containerPath, hostPath, true, false, containerId}
}