aboutsummaryrefslogtreecommitdiffhomepage
path: root/container/check/overlay.go
blob: ab907fbdb2989088f059e6c180d4bd56fb8ba39c (plain)
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
package check

import "strings"

const (
	// SpecialOverlayEscape is the escape string for overlay mount options.
	SpecialOverlayEscape = `\`
	// SpecialOverlayOption is the separator string between overlay mount options.
	SpecialOverlayOption = ","
	// SpecialOverlayPath is the separator string between overlay paths.
	SpecialOverlayPath = ":"
)

// EscapeOverlayDataSegment escapes a string for formatting into the data argument of an overlay mount call.
func EscapeOverlayDataSegment(s string) string {
	if s == "" {
		return ""
	}

	if f := strings.SplitN(s, "\x00", 2); len(f) > 0 {
		s = f[0]
	}

	return strings.NewReplacer(
		SpecialOverlayEscape, SpecialOverlayEscape+SpecialOverlayEscape,
		SpecialOverlayOption, SpecialOverlayEscape+SpecialOverlayOption,
		SpecialOverlayPath, SpecialOverlayEscape+SpecialOverlayPath,
	).Replace(s)
}