diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 072d238b17..88f3ecad9c 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -968,8 +968,22 @@ func addNetworks(quadletUnitFile *parser.UnitFile, groupName string, serviceUnit } } +// Systemd Specifiers start with % with the exception of %% +func startsWithSystemdSpecifier(filePath string) bool { + if len(filePath) == 0 || filePath[0] != '%' { + return false + } + + if len(filePath) > 1 && filePath[1] == '%' { + return false + } + + return true +} + func getAbsolutePath(quadletUnitFile *parser.UnitFile, filePath string) (string, error) { - if !filepath.IsAbs(filePath) { + // When the path starts with a Systemd specifier do not resolve what looks like a relative address + if !startsWithSystemdSpecifier(filePath) && !filepath.IsAbs(filePath) { if len(quadletUnitFile.Path) > 0 { filePath = filepath.Join(filepath.Dir(quadletUnitFile.Path), filePath) } else { diff --git a/test/e2e/quadlet/env-file.container b/test/e2e/quadlet/env-file.container index 9ae0de95ee..47bdf7cae4 100644 --- a/test/e2e/quadlet/env-file.container +++ b/test/e2e/quadlet/env-file.container @@ -1,9 +1,12 @@ ## assert-podman-final-args localhost/imagename -## assert-podman-args --env-file /opt/env/abs-1 --env-file /opt/env/abs-2 +## assert-podman-args --env-file /opt/env/abs-1 +## assert-podman-args --env-file /opt/env/abs-2 ## assert-podman-args-regex --env-file /.*/podman_test.*/quadlet/rel-1 +## assert-podman-args --env-file %h/env [Container] Image=localhost/imagename EnvironmentFile=/opt/env/abs-1 EnvironmentFile=/opt/env/abs-2 EnvironmentFile=rel-1 +EnvironmentFile=%h/env diff --git a/test/e2e/quadlet/volume.container b/test/e2e/quadlet/volume.container index 6484a9ff0e..934ce6f335 100644 --- a/test/e2e/quadlet/volume.container +++ b/test/e2e/quadlet/volume.container @@ -2,7 +2,8 @@ ## assert-podman-args -v /host/dir2:/container/volume2:Z ## assert-podman-args-regex -v .*/podman_test.*/quadlet/host/dir3:/container/volume3 ## assert-podman-args -v named:/container/named -## assert-podman-args -v systemd-quadlet:/container/quadlet localhost/imagename +## assert-podman-args -v systemd-quadlet:/container/quadlet +## assert-podman-args -v %h/container:/container/volume4 [Container] Image=localhost/imagename @@ -12,3 +13,4 @@ Volume=./host/dir3:/container/volume3 Volume=/container/empty Volume=named:/container/named Volume=quadlet.volume:/container/quadlet +Volume=%h/container:/container/volume4 diff --git a/test/system/252-quadlet.bats b/test/system/252-quadlet.bats index 34d94fa456..13dbcdac4e 100644 --- a/test/system/252-quadlet.bats +++ b/test/system/252-quadlet.bats @@ -558,4 +558,28 @@ EOF remove_secret $SECRET_NAME } +@test "quadlet - volume path using specifier" { + local tmp_path=$(mktemp -d --tmpdir=$PODMAN_TMPDIR quadlet.volume.XXXXXX) + local tmp_dir=${tmp_path#/tmp/} + local file_name="f$(random_string 10).txt" + local file_content="data_$(random_string 15)" + echo $file_content > $tmp_path/$file_name + + local quadlet_file=$PODMAN_TMPDIR/basic_$(random_string).container + cat > $quadlet_file <