[PATCH] 8295111: dpkg appears to have problems resolving symbolically linked native...
authorAlexey Semenyuk <asemenyuk@openjdk.org>
Tue, 30 Jul 2024 06:42:49 +0000 (08:42 +0200)
committerMatthias Klose <doko@ubuntu.com>
Tue, 30 Jul 2024 06:42:49 +0000 (08:42 +0200)
Applied-Upstream: 32946e1882e9b22c983cbba3c6bda3cc7295946a
Bug: https://bugs.openjdk.org/browse/JDK-8295111
Reviewed-by: almatvee
Gbp-Pq: Name jdk-8295111.patch

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java

index ccc36c3e166e329c68b7f8c0f9ba40580f234f8d..8a2dc5ea8f230d83ded5fabea42969fcc570dd3e 100644 (file)
@@ -195,6 +195,24 @@ public class LinuxDebBundler extends LinuxPackageBundler {
             Map<String, ? super Object> params,
             LibProvidersLookup libProvidersLookup) {
 
+        libProvidersLookup.setPackageLookup(file -> {
+            Path realPath = file.toRealPath();
+
+            try {
+                // Try the real path first as it works better on newer Ubuntu versions
+                return findProvidingPackages(realPath);
+            } catch (IOException ex) {
+                // Try the default path if differ
+                if (!realPath.toString().equals(file.toString())) {
+                    return findProvidingPackages(file);
+                } else {
+                    throw ex;
+                }
+            }
+        });
+    }
+
+    private static Stream<String> findProvidingPackages(Path file) throws IOException {
         //
         // `dpkg -S` command does glob pattern lookup. If not the absolute path
         // to the file is specified it might return mltiple package names.
@@ -237,32 +255,30 @@ public class LinuxDebBundler extends LinuxPackageBundler {
         // 4. Arch suffix should be stripped from accepted package names.
         //
 
-        libProvidersLookup.setPackageLookup(file -> {
-            Set<String> archPackages = new HashSet<>();
-            Set<String> otherPackages = new HashSet<>();
-
-            Executor.of(TOOL_DPKG, "-S", file.toString())
-                    .saveOutput(true).executeExpectSuccess()
-                    .getOutput().forEach(line -> {
-                        Matcher matcher = PACKAGE_NAME_REGEX.matcher(line);
-                        if (matcher.find()) {
-                            String name = matcher.group(1);
-                            if (name.endsWith(":" + DEB_ARCH)) {
-                                // Strip arch suffix
-                                name = name.substring(0,
-                                        name.length() - (DEB_ARCH.length() + 1));
-                                archPackages.add(name);
-                            } else {
-                                otherPackages.add(name);
-                            }
+        Set<String> archPackages = new HashSet<>();
+        Set<String> otherPackages = new HashSet<>();
+
+        Executor.of(TOOL_DPKG, "-S", file.toString())
+                .saveOutput(true).executeExpectSuccess()
+                .getOutput().forEach(line -> {
+                    Matcher matcher = PACKAGE_NAME_REGEX.matcher(line);
+                    if (matcher.find()) {
+                        String name = matcher.group(1);
+                        if (name.endsWith(":" + DEB_ARCH)) {
+                            // Strip arch suffix
+                            name = name.substring(0,
+                                    name.length() - (DEB_ARCH.length() + 1));
+                            archPackages.add(name);
+                        } else {
+                            otherPackages.add(name);
                         }
-                    });
+                    }
+                });
 
-            if (!archPackages.isEmpty()) {
-                return archPackages.stream();
-            }
-            return otherPackages.stream();
-        });
+        if (!archPackages.isEmpty()) {
+            return archPackages.stream();
+        }
+        return otherPackages.stream();
     }
 
     @Override