-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
189 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/cryptomator/frontend/fuse/mount/AbstractMounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.cryptomator.frontend.fuse.mount; | ||
|
||
import org.cryptomator.frontend.fuse.AdapterFactory; | ||
import org.cryptomator.frontend.fuse.FuseNioAdapter; | ||
|
||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Consumer; | ||
|
||
public abstract class AbstractMounter implements Mounter { | ||
|
||
private static final int MOUNT_TIMEOUT_MILLIS = 10000; | ||
private static final AtomicInteger MOUNT_COUNTER = new AtomicInteger(0); | ||
|
||
@Override | ||
public synchronized Mount mount(Path directory, EnvironmentVariables envVars, Consumer<Throwable> onFuseExit, boolean debug) throws FuseMountException { | ||
AtomicReference<Throwable> exception = new AtomicReference<>(); | ||
FuseNioAdapter fuseAdapter = AdapterFactory.createReadWriteAdapter(directory, // | ||
AdapterFactory.DEFAULT_MAX_FILENAMELENGTH, // | ||
envVars.getFileNameTranscoder()); | ||
//real mount op | ||
var mountThread = new Thread(() -> { | ||
try { | ||
fuseAdapter.mount(envVars.getMountPoint(), true, debug, envVars.getFuseFlags()); | ||
} catch (Exception e) { | ||
exception.set(e); | ||
} finally { | ||
onFuseExit.accept(exception.get()); | ||
} | ||
}); | ||
mountThread.setName("fuseMount-" + MOUNT_COUNTER.getAndIncrement() + "-main"); | ||
mountThread.setDaemon(true); | ||
mountThread.start(); | ||
|
||
// wait for mounted() is called, unlocking the barrier | ||
try { | ||
fuseAdapter.awaitInitCall(MOUNT_TIMEOUT_MILLIS); | ||
return createMountObject(fuseAdapter, envVars); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new FuseMountException("Mounting operation interrupted."); | ||
} catch (TimeoutException e) { | ||
if (exception.get() != null) { | ||
throw new FuseMountException(exception.get()); | ||
} else { | ||
throw new FuseMountException(e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public abstract String[] defaultMountFlags(); | ||
|
||
@Override | ||
public abstract boolean isApplicable(); | ||
|
||
protected abstract Mount createMountObject(FuseNioAdapter fuseNioAdapter, EnvironmentVariables envVars); | ||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/org/cryptomator/frontend/fuse/mount/CommandFailedException.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/org/cryptomator/frontend/fuse/mount/FuseMountException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.cryptomator.frontend.fuse.mount; | ||
|
||
public class FuseMountException extends Exception { | ||
|
||
public FuseMountException(String message) { | ||
super(message); | ||
} | ||
|
||
public FuseMountException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.