mirror of
https://github.com/containers/podman.git
synced 2025-11-30 18:18:18 +08:00
Escape RequiresMountsFor value
Signed-off-by: Dmitry Konishchev <konishchev@gmail.com>
This commit is contained in:
@@ -879,6 +879,15 @@ func (f *UnitFile) Add(groupName string, key string, value string) {
|
||||
group.add(key, value)
|
||||
}
|
||||
|
||||
func (f *UnitFile) AddEscaped(groupName string, key string, value string) {
|
||||
if wordNeedEscape(value) {
|
||||
var escaped strings.Builder
|
||||
appendEscapeWord(&escaped, value)
|
||||
value = escaped.String()
|
||||
}
|
||||
f.Add(groupName, key, value)
|
||||
}
|
||||
|
||||
func (f *UnitFile) AddCmdline(groupName string, key string, args []string) {
|
||||
f.Add(groupName, key, escapeWords(args))
|
||||
}
|
||||
|
||||
@@ -1151,7 +1151,7 @@ func ConvertVolume(volume *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, i
|
||||
if devValid {
|
||||
podman.add("--opt", fmt.Sprintf("type=%s", devType))
|
||||
if devType == "bind" {
|
||||
service.Add(UnitGroup, "RequiresMountsFor", dev)
|
||||
service.AddEscaped(UnitGroup, "RequiresMountsFor", dev)
|
||||
}
|
||||
} else {
|
||||
return nil, warnings, fmt.Errorf("key Type can't be used without Device")
|
||||
@@ -1929,7 +1929,7 @@ func handleStorageSource(quadletUnitFile, serviceUnitFile *parser.UnitFile, sour
|
||||
}
|
||||
if source[0] == '/' {
|
||||
// Absolute path
|
||||
serviceUnitFile.Add(UnitGroup, "RequiresMountsFor", source)
|
||||
serviceUnitFile.AddEscaped(UnitGroup, "RequiresMountsFor", source)
|
||||
} else if strings.HasSuffix(source, ".volume") || (checkImage && strings.HasSuffix(source, ".image")) || strings.HasSuffix(source, ".artifact") {
|
||||
sourceUnitInfo, ok := unitsInfoMap[source]
|
||||
if !ok {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
[Container]
|
||||
Image=localhost/imagename
|
||||
## assert-has-key Unit RequiresMountsFor "/path/on/host"
|
||||
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host,destination=/path/in/container"
|
||||
Mount=type=bind,source=/path/on/host,destination=/path/in/container
|
||||
## assert-has-key Unit RequiresMountsFor "\"/path/on/host\\x20with\\x20spaces\""
|
||||
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host with spaces,dst=/path"
|
||||
Mount="type=bind,src=/path/on/host with spaces,dst=/path"
|
||||
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host,dst=/path/in/container,relabel=shared"
|
||||
Mount=type=bind,src=/path/on/host,dst=/path/in/container,relabel=shared
|
||||
## assert-podman-args-key-val "--mount" "," "type=bind,source=/path/on/host,dst=/path/in/container,relabel=shared,U=true"
|
||||
|
||||
Reference in New Issue
Block a user