From 741edbec0df6f7dca141f4b3f5b51781b1f48a9b Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 22 Dec 2023 23:32:18 +0000 Subject: [PATCH] Don't fail when we can't resolve our own executable --- .../io/xpipe/core/util/XPipeInstallation.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java index 7445d369..4d25e523 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java @@ -5,6 +5,7 @@ import io.xpipe.core.store.FileNames; import lombok.Getter; import lombok.SneakyThrows; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.InvalidPathException; @@ -77,10 +78,10 @@ public class XPipeInstallation { public static Path getCurrentInstallationBasePath() { // We should always have a command associated with the current process, otherwise something went seriously wrong // Resolve any possible links to a real path - Path path = Path.of(ProcessHandle.current().info().command().orElseThrow()).toRealPath(); + Path path = toRealPathIfPossible(Path.of(ProcessHandle.current().info().command().orElseThrow())); // Check if the process was started using a relative path, and adapt it if necessary if (!path.isAbsolute()) { - path = Path.of(System.getProperty("user.dir")).resolve(path).toRealPath(); + path = toRealPathIfPossible(Path.of(System.getProperty("user.dir")).resolve(path)); } var name = path.getFileName().toString(); @@ -97,6 +98,16 @@ public class XPipeInstallation { } } + private static Path toRealPathIfPossible(Path p) { + try { + // Under certain conditions, e.g. when running on a ramdisk, path resolution might fail. + // This is however not a big problem in that case, so we ignore it + return p.toRealPath(); + } catch (IOException e) { + return p; + } + } + public static boolean isInstallationDistribution() { var base = getCurrentInstallationBasePath(); if (OsType.getLocal().equals(OsType.MACOS)) {