Skip to content

Commit

Permalink
fallback to System.loadLibrary(...)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
overheadhunter committed Sep 27, 2023
1 parent e4f5cf1 commit 6fb0be0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
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.
*/
@SupportedPlatform(os = OperatingSystem.MAC, arch = Architecture.AMD64)
@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;

Expand All @@ -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);
}
Expand Down

0 comments on commit 6fb0be0

Please sign in to comment.