podman

Форк
0
/
parse.go 
48 строк · 1.5 Кб
1
package copy
2

3
import (
4
	"fmt"
5
	"strings"
6
)
7

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.
12
//
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)
19

20
	if len(sourcePath) == 0 || len(destPath) == 0 {
21
		return "", "", "", "", fmt.Errorf("invalid arguments %q, %q: you must specify paths", source, destination)
22
	}
23

24
	return sourceContainer, sourcePath, destContainer, destPath, nil
25
}
26

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) {
32
	if len(input) == 0 {
33
		return
34
	}
35
	path = input
36

37
	// If the input starts with a dot or slash, it cannot refer to a
38
	// container.
39
	if input[0] == '.' || input[0] == '/' {
40
		return
41
	}
42

43
	if parsedContainer, parsedPath, ok := strings.Cut(path, ":"); ok {
44
		container = parsedContainer
45
		path = parsedPath
46
	}
47
	return
48
}
49

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.