diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-07 23:56:19 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-07 23:56:19 +0900 |
| commit | 1f0226f7e01822a2a5b37d8626b59b7b6f4d0144 (patch) | |
| tree | 47ca771c20a1073f4c2743c7c1b4189f66ddf336 /container/check/overlay.go | |
| parent | 584ce3da685352847e5c6189e5050bd5cb0307e9 (diff) | |
container/check: relocate overlay escape
This is used in hst to format strings.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/check/overlay.go')
| -rw-r--r-- | container/check/overlay.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/container/check/overlay.go b/container/check/overlay.go new file mode 100644 index 00000000..ab907fbd --- /dev/null +++ b/container/check/overlay.go @@ -0,0 +1,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) +} |
