From c7beb4a93c9be0aceb8599dc0d77bb12a5450962 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Tue, 3 Apr 2018 17:32:26 +0200 Subject: [PATCH] Default to FUSE. Use WebDAV as Backup, if FUSE isn't supported --- .../cryptomator/common/settings/Settings.java | 2 +- main/pom.xml | 2 +- .../org/cryptomator/ui/model/FuseVolume.java | 68 ++++++++----------- .../org/cryptomator/ui/model/VaultModule.java | 9 ++- 4 files changed, 36 insertions(+), 45 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java index f3b8a169f..bd32a1cb6 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/Settings.java @@ -32,7 +32,7 @@ public class Settings { public static final int DEFAULT_NUM_TRAY_NOTIFICATIONS = 3; public static final String DEFAULT_GVFS_SCHEME = "dav"; public static final boolean DEFAULT_DEBUG_MODE = false; - public static final VolumeImpl DEFAULT_VOLUME_IMPL = VolumeImpl.WEBDAV; + public static final VolumeImpl DEFAULT_VOLUME_IMPL = VolumeImpl.FUSE; private final ObservableList directories = FXCollections.observableArrayList(VaultSettings::observables); private final BooleanProperty checkForUpdates = new SimpleBooleanProperty(DEFAULT_CHECK_FOR_UDPATES); diff --git a/main/pom.xml b/main/pom.xml index 533e3382a..c6f445ca7 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -28,7 +28,7 @@ 1.5.1 1.0.4 2.0.0 - 0.1.2 + 0.1.3 2.5 3.6 diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java b/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java index 2b8000344..e1c6907d6 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java @@ -1,22 +1,23 @@ package org.cryptomator.ui.model; -import org.apache.commons.lang3.SystemUtils; -import org.cryptomator.common.settings.VaultSettings; -import org.cryptomator.cryptofs.CryptoFileSystem; - -import org.cryptomator.frontend.fuse.mount.EnvironmentVariables; -import org.cryptomator.frontend.fuse.mount.FuseMount; -import org.cryptomator.frontend.fuse.mount.FuseMountFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; import java.io.IOException; import java.nio.file.DirectoryNotEmptyException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import javax.inject.Inject; + +import org.apache.commons.lang3.SystemUtils; +import org.cryptomator.common.settings.VaultSettings; +import org.cryptomator.cryptofs.CryptoFileSystem; +import org.cryptomator.frontend.fuse.mount.EnvironmentVariables; +import org.cryptomator.frontend.fuse.mount.FuseMountFactory; +import org.cryptomator.frontend.fuse.mount.FuseNotSupportedException; +import org.cryptomator.frontend.fuse.mount.Mount; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + @VaultModule.PerVault public class FuseVolume implements Volume { @@ -28,10 +29,10 @@ public class FuseVolume implements Volume { private static final String DEFAULT_MOUNTROOTPATH_MAC = System.getProperty("user.home") + "/Library/Application Support/Cryptomator"; private static final String DEFAULT_MOUNTROOTPATH_LINUX = System.getProperty("user.home") + "/.Cryptomator"; - private final FuseMount fuseMnt; private final VaultSettings vaultSettings; private final WindowsDriveLetters windowsDriveLetters; + private Mount fuseMnt; private CryptoFileSystem cfs; private Path mountPath; private boolean extraDirCreated; @@ -40,12 +41,11 @@ public class FuseVolume implements Volume { public FuseVolume(VaultSettings vaultSettings, WindowsDriveLetters windowsDriveLetters) { this.vaultSettings = vaultSettings; this.windowsDriveLetters = windowsDriveLetters; - this.fuseMnt = FuseMountFactory.createMountObject(); this.extraDirCreated = false; } @Override - public void prepare(CryptoFileSystem fs) throws IOException { + public void prepare(CryptoFileSystem fs) throws IOException, FuseNotSupportedException { this.cfs = fs; String mountPath; if (SystemUtils.IS_OS_WINDOWS) { @@ -62,8 +62,7 @@ public class FuseVolume implements Volume { mountPath = vaultSettings.individualMountPath().get(); } else { //choose default path & create extra directory - mountPath = createDirIfNotExist(SystemUtils.IS_OS_MAC ? DEFAULT_MOUNTROOTPATH_MAC : DEFAULT_MOUNTROOTPATH_LINUX, - vaultSettings.mountName().get()); + mountPath = createDirIfNotExist(SystemUtils.IS_OS_MAC ? DEFAULT_MOUNTROOTPATH_MAC : DEFAULT_MOUNTROOTPATH_LINUX, vaultSettings.mountName().get()); extraDirCreated = true; } this.mountPath = Paths.get(mountPath).toAbsolutePath(); @@ -84,10 +83,10 @@ public class FuseVolume implements Volume { try { EnvironmentVariables envVars = EnvironmentVariables.create() .withMountName(vaultSettings.mountName().getValue()) - .withMountPath(mountPath.toString()) + .withMountPath(mountPath) .build(); - fuseMnt.mount(cfs.getPath("/"), envVars); - } catch (Exception e) { + this.fuseMnt = FuseMountFactory.getMounter().mount(cfs.getPath("/"), envVars); + } catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) { throw new CommandFailedException("Unable to mount Filesystem", e); } } @@ -95,7 +94,7 @@ public class FuseVolume implements Volume { @Override public void reveal() throws CommandFailedException { try { - fuseMnt.reveal(); + fuseMnt.revealInFileManager(); } catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) { LOG.info("Revealing the vault in file manger failed: " + e.getMessage()); throw new CommandFailedException(e); @@ -104,24 +103,16 @@ public class FuseVolume implements Volume { @Override public synchronized void unmount() throws CommandFailedException { - if (cfs.getStats().pollBytesRead() == 0 && cfs.getStats().pollBytesWritten() == 0) { - unmountRaw(); - } else { - throw new CommandFailedException("Pending read or write operations."); + try { + fuseMnt.close(); + } catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) { + throw new CommandFailedException(e); } } @Override public synchronized void unmountForced() throws CommandFailedException { - this.unmountRaw(); - } - - private synchronized void unmountRaw() throws CommandFailedException { - try { - fuseMnt.unmount(); - } catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) { - throw new CommandFailedException(e); - } + unmount(); } @Override @@ -137,22 +128,17 @@ public class FuseVolume implements Volume { @Override public String getMountUri() { - return Paths.get(fuseMnt.getMountPath()).toUri().toString(); + return ""; } - /** - * TODO: change this to a real implementation - * - * @return - */ @Override public boolean isSupported() { - return true; + return FuseMountFactory.isFuseSupported(); } @Override public boolean supportsForcedUnmount() { - return true; + return false; } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java index 0012b63e5..93c130522 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/VaultModule.java @@ -46,10 +46,15 @@ public class VaultModule { public Volume provideNioAdpater(Settings settings, WebDavVolume webDavVolume, FuseVolume fuseVolume) { VolumeImpl impl = settings.volumeImpl().get(); switch (impl) { + case FUSE: + if (fuseVolume.isSupported()) { + return fuseVolume; + } else { + settings.volumeImpl().set(VolumeImpl.WEBDAV); + // fallthrough to WEBDAV + } case WEBDAV: return webDavVolume; - case FUSE: - return fuseVolume; default: throw new IllegalStateException("Unsupported NioAdapter: " + impl); }