8
// ParseSourceAndDestination parses the source and destination input into a
9
// possibly specified container and path. The input format is described in
10
// podman-cp(1) as "[nameOrID:]path". Colons in paths are supported as long
11
// they start with a dot or slash.
13
// It returns, in order, the source container and path, followed by the
14
// destination container and path, and an error. Note that exactly one
15
// container must be specified.
16
func ParseSourceAndDestination(source, destination string) (string, string, string, string, error) {
17
sourceContainer, sourcePath := parseUserInput(source)
18
destContainer, destPath := parseUserInput(destination)
20
if len(sourcePath) == 0 || len(destPath) == 0 {
21
return "", "", "", "", fmt.Errorf("invalid arguments %q, %q: you must specify paths", source, destination)
24
return sourceContainer, sourcePath, destContainer, destPath, nil
27
// parseUserInput parses the input string and returns, if specified, the name
28
// or ID of the container and the path. The input format is described in
29
// podman-cp(1) as "[nameOrID:]path". Colons in paths are supported as long
30
// they start with a dot or slash.
31
func parseUserInput(input string) (container string, path string) {
37
// If the input starts with a dot or slash, it cannot refer to a
39
if input[0] == '.' || input[0] == '/' {
43
if parsedContainer, parsedPath, ok := strings.Cut(path, ":"); ok {
44
container = parsedContainer