From 6d015a949e27f20c86409c7d78053f0b0493f165 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 17 Mar 2026 15:35:58 +0900 Subject: check: move from container This package is not container specific, and widely used across the project. Signed-off-by: Ophestra --- check/overlay.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 check/overlay.go (limited to 'check/overlay.go') diff --git a/check/overlay.go b/check/overlay.go new file mode 100644 index 00000000..fbbcd1e6 --- /dev/null +++ b/check/overlay.go @@ -0,0 +1,30 @@ +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 system 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) +} -- cgit v1.3.1