Skip to content

Commit

Permalink
add lib loading fallback for linux (#81) (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerCeMan committed Sep 15, 2019
1 parent 3c9a3f5 commit 64a4588
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/main/java/ru/serce/jnrfuse/AbstractFuseFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
import jnr.posix.util.Platform;
import ru.serce.jnrfuse.struct.*;
import ru.serce.jnrfuse.utils.MountUtils;
import ru.serce.jnrfuse.utils.WinPathUtils;
import ru.serce.jnrfuse.utils.SecurityUtils;
import ru.serce.jnrfuse.utils.WinPathUtils;

import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Set;
import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

Expand All @@ -34,13 +36,9 @@ public abstract class AbstractFuseFS implements FuseFS {
private volatile Pointer fusePointer;

public AbstractFuseFS() {
LibraryLoader<LibFuse> loader = LibraryLoader.create(LibFuse.class).failImmediately();
jnr.ffi.Platform p = jnr.ffi.Platform.getNativePlatform();
LibFuse libFuse = null;
switch (p.getOS()) {
case LINUX:
libFuse = loader.load("libfuse.so.2");
break;
case DARWIN:
for (String library : osxFuseLibraries) {
try {
Expand All @@ -60,15 +58,17 @@ public AbstractFuseFS() {
break;
case WINDOWS:
String winFspPath = WinPathUtils.getWinFspPath();
libFuse = loader.load(winFspPath);
break;
default:
// try fuse
libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load(winFspPath);
break;
case LINUX:
default: // Assume linux since we have no further OS evidence
try {
// assume linux
libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("libfuse.so.2");
} catch (Throwable e) {
// Try loading library by going through the library mapping process, see j.l.System.mapLibraryName
libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("fuse");
} catch (Throwable e) {
// Try loading the dynamic library directly which will end up calling dlopen directly, see
// com.kenai.jffi.Foreign.dlopen
libFuse = LibraryLoader.create(LibFuse.class).failImmediately().load("libfuse.so.2");
}
}
this.libFuse = libFuse;
Expand All @@ -84,9 +84,9 @@ public FuseContext getContext() {

private void init(FuseOperations fuseOperations) {
notImplementedMethods = Arrays.stream(getClass().getMethods())
.filter(method -> method.getAnnotation(NotImplemented.class) != null)
.map(Method::getName)
.collect(Collectors.toSet());
.filter(method -> method.getAnnotation(NotImplemented.class) != null)
.map(Method::getName)
.collect(Collectors.toSet());

AbstractFuseFS fuse = this;
if (isImplemented("getattr")) {
Expand Down

0 comments on commit 64a4588

Please sign in to comment.