mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
Fix machine volumes with long path and paths with dashes
AppleHV accepts a max 36 bytes for mount tags. Instead of using the fully qualified path for the mount tag, SHA256 the path, and truncate the shasum to 36 bytes. Also correctly escape dashes in mounted paths. Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -428,13 +428,17 @@ func splitString(s string, separators string, flags SplitFlags) ([]string, error
|
||||
return splitStringAppend(make([]string, 0), s, separators, flags)
|
||||
}
|
||||
|
||||
func charNeedEscape(c rune) bool {
|
||||
func charNeedEscape(c rune, isPath bool) bool {
|
||||
if c > 128 {
|
||||
return false /* unicode is ok */
|
||||
}
|
||||
|
||||
pathRune := (isPath && c == '-') ||
|
||||
(isPath && c == '/')
|
||||
|
||||
return unicode.IsSpace(c) ||
|
||||
unicode.IsControl(c) ||
|
||||
pathRune ||
|
||||
c == '"' ||
|
||||
c == '\'' ||
|
||||
c == '\\'
|
||||
@ -442,18 +446,22 @@ func charNeedEscape(c rune) bool {
|
||||
|
||||
func wordNeedEscape(word string) bool {
|
||||
for _, c := range word {
|
||||
if charNeedEscape(c) {
|
||||
if charNeedEscape(c, false) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func appendEscapeWord(escaped *strings.Builder, word string) {
|
||||
escaped.WriteRune('"')
|
||||
for _, c := range word {
|
||||
if charNeedEscape(c) {
|
||||
escapeString(escaped, word, false)
|
||||
escaped.WriteRune('"')
|
||||
}
|
||||
|
||||
func escapeString(escaped *strings.Builder, word string, isPath bool) {
|
||||
for i, c := range word {
|
||||
if charNeedEscape(c, isPath) {
|
||||
switch c {
|
||||
case '\a':
|
||||
escaped.WriteString("\\a")
|
||||
@ -477,6 +485,10 @@ func appendEscapeWord(escaped *strings.Builder, word string) {
|
||||
escaped.WriteString("\\\"")
|
||||
case '\'':
|
||||
escaped.WriteString("'")
|
||||
case '/':
|
||||
if isPath && i != 0 {
|
||||
escaped.WriteString("-")
|
||||
}
|
||||
default:
|
||||
escaped.WriteString(fmt.Sprintf("\\x%.2x", c))
|
||||
}
|
||||
@ -484,7 +496,6 @@ func appendEscapeWord(escaped *strings.Builder, word string) {
|
||||
escaped.WriteRune(c)
|
||||
}
|
||||
}
|
||||
escaped.WriteRune('"')
|
||||
}
|
||||
|
||||
func escapeWords(words []string) string {
|
||||
@ -500,6 +511,5 @@ func escapeWords(words []string) string {
|
||||
escaped.WriteString(word)
|
||||
}
|
||||
}
|
||||
|
||||
return escaped.String()
|
||||
}
|
||||
|
@ -932,3 +932,9 @@ func (f *UnitFile) GetTemplateParts() (string, string) {
|
||||
}
|
||||
return parts[0] + "@" + ext, parts[1]
|
||||
}
|
||||
|
||||
func PathEscape(path string) string {
|
||||
var escaped strings.Builder
|
||||
escapeString(&escaped, path, true)
|
||||
return escaped.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user