From 6fb0be062492a5f29daf752aac3339e306858b3e Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 27 Sep 2023 10:22:41 +0200 Subject: [PATCH] fallback to `System.loadLibrary(...)` when `fuse.lib.path` is not set explicitly, allowing to use Java's default lib lookup mechanism based on `java.library.path` on Linux + macOS --- .../jfuse/linux/aarch64/LinuxFuseBuilder.java | 4 ++-- .../jfuse/linux/amd64/LinuxFuseBuilder.java | 4 ++-- .../cryptomator/jfuse/mac/MacFuseBuilder.java | 22 ++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/jfuse-linux-aarch64/src/main/java/org/cryptomator/jfuse/linux/aarch64/LinuxFuseBuilder.java b/jfuse-linux-aarch64/src/main/java/org/cryptomator/jfuse/linux/aarch64/LinuxFuseBuilder.java index 11842b17..c76abf3f 100644 --- a/jfuse-linux-aarch64/src/main/java/org/cryptomator/jfuse/linux/aarch64/LinuxFuseBuilder.java +++ b/jfuse-linux-aarch64/src/main/java/org/cryptomator/jfuse/linux/aarch64/LinuxFuseBuilder.java @@ -14,7 +14,7 @@ @SupportedPlatform(os = OperatingSystem.LINUX, arch = Architecture.ARM64) public class LinuxFuseBuilder implements FuseBuilder { - private static final String DEFAULT_LIB_PATH = "/lib/aarch64-linux-gnu/libfuse3.so.3"; + private static final String DEFAULT_LIBNAME = "fuse3"; private static final Errno ERRNO = new LinuxErrno(); private String libraryPath; @@ -39,7 +39,7 @@ public Fuse build(FuseOperations fuseOperations) throws UnsatisfiedLinkError { if (libraryPath != null) { System.load(libraryPath); } else { - System.load(DEFAULT_LIB_PATH); + System.loadLibrary(DEFAULT_LIBNAME); } return new FuseImpl(fuseOperations); } diff --git a/jfuse-linux-amd64/src/main/java/org/cryptomator/jfuse/linux/amd64/LinuxFuseBuilder.java b/jfuse-linux-amd64/src/main/java/org/cryptomator/jfuse/linux/amd64/LinuxFuseBuilder.java index 24ef1284..bdfebc18 100644 --- a/jfuse-linux-amd64/src/main/java/org/cryptomator/jfuse/linux/amd64/LinuxFuseBuilder.java +++ b/jfuse-linux-amd64/src/main/java/org/cryptomator/jfuse/linux/amd64/LinuxFuseBuilder.java @@ -14,7 +14,7 @@ @SupportedPlatform(os = OperatingSystem.LINUX, arch = Architecture.AMD64) public class LinuxFuseBuilder implements FuseBuilder { - private static final String DEFAULT_LIB_PATH = "/lib/x86_64-linux-gnu/libfuse3.so.3"; + private static final String DEFAULT_LIBNAME = "fuse3"; private static final Errno ERRNO = new LinuxErrno(); private String libraryPath; @@ -39,7 +39,7 @@ public Fuse build(FuseOperations fuseOperations) throws UnsatisfiedLinkError { if (libraryPath != null) { System.load(libraryPath); } else { - System.load(DEFAULT_LIB_PATH); + System.loadLibrary(DEFAULT_LIBNAME); } return new FuseImpl(fuseOperations); } diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/MacFuseBuilder.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/MacFuseBuilder.java index e78c04cb..b9304eb8 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/MacFuseBuilder.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/MacFuseBuilder.java @@ -8,9 +8,6 @@ import org.cryptomator.jfuse.api.platforms.OperatingSystem; import org.cryptomator.jfuse.api.platforms.SupportedPlatform; -import java.nio.file.Files; -import java.nio.file.Path; - /** * Builds FUSE file system instances on macOS. */ @@ -18,8 +15,8 @@ @SupportedPlatform(os = OperatingSystem.MAC, arch = Architecture.ARM64) public class MacFuseBuilder implements FuseBuilder { - private static final String DEFAULT_MACFUSE_PATH = "/usr/local/lib/libfuse.dylib"; - private static final String DEFAULT_FUSET_PATH = "/usr/local/lib/libfuse-t.dylib"; + private static final String DEFAULT_MACFUSE_LIBNAME = "fuse"; + private static final String DEFAULT_FUSET_LIBNAMNE = "fuse-t"; private static final Errno ERRNO = new MacErrno(); private String libraryPath; @@ -43,12 +40,17 @@ public void setLibraryPath(String libraryPath) { public Fuse build(FuseOperations fuseOperations) throws UnsatisfiedLinkError { if (libraryPath != null) { System.load(libraryPath); - } else if (Files.exists(Path.of(DEFAULT_MACFUSE_PATH))) { - System.load(DEFAULT_MACFUSE_PATH); - } else if (Files.exists(Path.of(DEFAULT_FUSET_PATH))) { - System.load(DEFAULT_FUSET_PATH); } else { - System.loadLibrary("fuse"); + try { + System.loadLibrary(DEFAULT_MACFUSE_LIBNAME); + } catch (UnsatisfiedLinkError errorLoadingMacFuse) { + try { + System.loadLibrary(DEFAULT_FUSET_LIBNAMNE); + } catch (UnsatisfiedLinkError errorLoadingFuseT) { + errorLoadingFuseT.addSuppressed(errorLoadingMacFuse); + throw errorLoadingFuseT; + } + } } return new FuseImpl(fuseOperations); }