From db7ab714570bb49ed55710b8219f14ce8b956346 Mon Sep 17 00:00:00 2001 From: Michal Karm Babacek Date: Mon, 30 May 2022 21:27:06 +0200 Subject: [PATCH] Podman on Windows needs one /, not two // prefix fixes #25865 --- .../NativeImageBuildLocalContainerRunner.java | 3 ++- .../pkg/steps/UpxCompressionBuildStep.java | 3 ++- .../io/quarkus/deployment/util/FileUtil.java | 5 +++-- .../quarkus/deployment/util/FileUtilTest.java | 17 +++++++++-------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java index da449581e169e..8cabc251e4a3b 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildLocalContainerRunner.java @@ -40,7 +40,8 @@ protected List getContainerRuntimeBuildArgs() { List containerRuntimeArgs = super.getContainerRuntimeBuildArgs(); String volumeOutputPath = outputPath; if (SystemUtils.IS_OS_WINDOWS) { - volumeOutputPath = FileUtil.translateToVolumePath(volumeOutputPath); + volumeOutputPath = FileUtil.translateToVolumePath(volumeOutputPath, + containerRuntime == ContainerRuntimeUtil.ContainerRuntime.PODMAN); } Collections.addAll(containerRuntimeArgs, "-v", diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java index 043ff6fd1e38c..a1023f7fd4448 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java @@ -122,7 +122,8 @@ private boolean runUpxInContainer(NativeImageBuildItem nativeImage, NativeConfig String volumeOutputPath = nativeImage.getPath().toFile().getParentFile().getAbsolutePath(); if (SystemUtils.IS_OS_WINDOWS) { - volumeOutputPath = FileUtil.translateToVolumePath(volumeOutputPath); + volumeOutputPath = FileUtil.translateToVolumePath(volumeOutputPath, + containerRuntime == ContainerRuntimeUtil.ContainerRuntime.PODMAN); } else if (SystemUtils.IS_OS_LINUX) { String uid = getLinuxID("-ur"); String gid = getLinuxID("-gr"); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/util/FileUtil.java b/core/deployment/src/main/java/io/quarkus/deployment/util/FileUtil.java index 711072d50b166..de20b26d2f03f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/util/FileUtil.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/util/FileUtil.java @@ -78,14 +78,15 @@ public static byte[] readFileContents(InputStream inputStream) throws IOExceptio * @param windowsStylePath A path formatted in Windows-style, e.g. "C:\foo\bar". * @return A translated path accepted by Docker, e.g. "//c/foo/bar". */ - public static String translateToVolumePath(String windowsStylePath) { + public static String translateToVolumePath(String windowsStylePath, boolean isPodman) { String translated = windowsStylePath.replace('\\', '/'); Pattern p = Pattern.compile("^(\\w)(?:$|:(/)?(.*))"); Matcher m = p.matcher(translated); if (m.matches()) { String slash = Optional.ofNullable(m.group(2)).orElse("/"); String path = Optional.ofNullable(m.group(3)).orElse(""); - return "//" + m.group(1).toLowerCase() + slash + path; + // Ad `/' and `//' see https://github.com/containers/podman/issues/14414 + return (isPodman ? "/" : "//") + m.group(1).toLowerCase() + slash + path; } return translated; } diff --git a/core/deployment/src/test/java/io/quarkus/deployment/util/FileUtilTest.java b/core/deployment/src/test/java/io/quarkus/deployment/util/FileUtilTest.java index dcc09761c4738..97733a37bde7f 100644 --- a/core/deployment/src/test/java/io/quarkus/deployment/util/FileUtilTest.java +++ b/core/deployment/src/test/java/io/quarkus/deployment/util/FileUtilTest.java @@ -10,19 +10,20 @@ public class FileUtilTest { @Test public void testTranslateToVolumePath() { // Windows-Style paths are formatted. - assertEquals("//c/", translateToVolumePath("C")); - assertEquals("//c/", translateToVolumePath("C:")); - assertEquals("//c/", translateToVolumePath("C:\\")); - assertEquals("//c/Users", translateToVolumePath("C:\\Users")); + assertEquals("/c/tmp/code-with-quarkus", translateToVolumePath("C:\\tmp\\code-with-quarkus", true)); + assertEquals("//c/", translateToVolumePath("C", false)); + assertEquals("//c/", translateToVolumePath("C:", false)); + assertEquals("//c/", translateToVolumePath("C:\\", false)); + assertEquals("//c/Users", translateToVolumePath("C:\\Users", false)); assertEquals("//c/Users/Quarkus/lambdatest-1.0-SNAPSHOT-native-image-source-jar", - translateToVolumePath("C:\\Users\\Quarkus\\lambdatest-1.0-SNAPSHOT-native-image-source-jar")); + translateToVolumePath("C:\\Users\\Quarkus\\lambdatest-1.0-SNAPSHOT-native-image-source-jar", false)); // Side effect for Unix-style path. - assertEquals("//c/Users/Quarkus", translateToVolumePath("c:/Users/Quarkus")); + assertEquals("//c/Users/Quarkus", translateToVolumePath("c:/Users/Quarkus", false)); // Side effects for fancy inputs - for the sake of documentation. - assertEquals("something/bizarre", translateToVolumePath("something\\bizarre")); - assertEquals("something.bizarre", translateToVolumePath("something.bizarre")); + assertEquals("something/bizarre", translateToVolumePath("something\\bizarre", false)); + assertEquals("something.bizarre", translateToVolumePath("something.bizarre", false)); } }