diff --git a/pkg/systemd/parser/unitfile.go b/pkg/systemd/parser/unitfile.go index 099145f592..19556e0cd7 100644 --- a/pkg/systemd/parser/unitfile.go +++ b/pkg/systemd/parser/unitfile.go @@ -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)) } diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 28ac14af96..6c11dd98fb 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -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 { diff --git a/test/e2e/quadlet/mount.container b/test/e2e/quadlet/mount.container index b0a4713785..2327cf8cf3 100644 --- a/test/e2e/quadlet/mount.container +++ b/test/e2e/quadlet/mount.container @@ -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"