Browse Source

empty custom mount point checks

Sebastian Stenzel 6 years ago
parent
commit
f52b2f323a

+ 10 - 0
main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java

@@ -5,6 +5,7 @@
  *******************************************************************************/
 package org.cryptomator.common.settings;
 
+import com.google.common.base.Strings;
 import javafx.beans.Observable;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.ObjectProperty;
@@ -20,6 +21,7 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
 import java.util.Base64;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.UUID;
 
 /**
@@ -133,6 +135,14 @@ public class VaultSettings {
 		return individualMountPath;
 	}
 
+	public Optional<String> getIndividualMountPath() {
+		if (usesIndividualMountPath.get()) {
+			return Optional.ofNullable(Strings.emptyToNull(individualMountPath.get()));
+		} else {
+			return Optional.empty();
+		}
+	}
+
 	public BooleanProperty usesReadOnlyMode() {
 		return usesReadOnlyMode;
 	}

+ 3 - 3
main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java

@@ -246,10 +246,10 @@ public class UnlockController implements ViewController {
 		useReadOnlyMode.setSelected(vaultSettings.usesReadOnlyMode().get());
 		if (!settings.preferredVolumeImpl().get().equals(VolumeImpl.WEBDAV)) {
 			useCustomMountPoint.setSelected(vaultSettings.usesIndividualMountPath().get());
-			if (vaultSettings.individualMountPath().get() == null) {
-				customMountPointLabel.textProperty().setValue(localization.getString("unlock.label.chooseMountPath"));
+			if (Strings.isNullOrEmpty(vaultSettings.individualMountPath().get())) {
+				customMountPointLabel.setText(localization.getString("unlock.label.chooseMountPath"));
 			} else {
-				customMountPointLabel.textProperty().setValue(displayablePath(vaultSettings.individualMountPath().getValueSafe()));
+				customMountPointLabel.setText(displayablePath(vaultSettings.individualMountPath().getValueSafe()));
 			}
 		}
 

+ 5 - 3
main/ui/src/main/java/org/cryptomator/ui/model/DokanyVolume.java

@@ -17,6 +17,7 @@ import java.nio.file.Files;
 import java.nio.file.NotDirectoryException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Optional;
 import java.util.concurrent.ExecutorService;
 
 public class DokanyVolume implements Volume {
@@ -49,7 +50,7 @@ public class DokanyVolume implements Volume {
 		try {
 			this.mount = mountFactory.mount(fs.getPath("/"), mountPath, mountName, FS_TYPE_NAME);
 		} catch (MountFailedException e) {
-			if (vaultSettings.usesIndividualMountPath().get()) {
+			if (vaultSettings.getIndividualMountPath().isPresent()) {
 				LOG.warn("Failed to mount vault into {}. Is this directory currently accessed by another process (e.g. Windows Explorer)?", mountPath);
 			}
 			throw new VolumeException("Unable to mount Filesystem", e);
@@ -57,8 +58,9 @@ public class DokanyVolume implements Volume {
 	}
 
 	private Path getMountPoint() throws VolumeException, IOException {
-		if (vaultSettings.usesIndividualMountPath().get()) {
-			Path customMountPoint = Paths.get(vaultSettings.individualMountPath().get());
+		Optional<String> optionalCustomMountPoint = vaultSettings.getIndividualMountPath();
+		if (optionalCustomMountPoint.isPresent()) {
+			Path customMountPoint = Paths.get(optionalCustomMountPoint.get());
 			checkProvidedMountPoint(customMountPoint);
 			return customMountPoint;
 		} else if (!Strings.isNullOrEmpty(vaultSettings.winDriveLetter().get())) {

+ 4 - 2
main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java

@@ -20,6 +20,7 @@ import java.nio.file.Files;
 import java.nio.file.NotDirectoryException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Optional;
 
 public class FuseVolume implements Volume {
 
@@ -43,8 +44,9 @@ public class FuseVolume implements Volume {
 
 	@Override
 	public void mount(CryptoFileSystem fs) throws IOException, FuseNotSupportedException, VolumeException {
-		if (vaultSettings.usesIndividualMountPath().get()) {
-			Path customMountPoint = Paths.get(vaultSettings.individualMountPath().get());
+		Optional<String> optionalCustomMountPoint = vaultSettings.getIndividualMountPath();
+		if (optionalCustomMountPoint.isPresent()) {
+			Path customMountPoint = Paths.get(optionalCustomMountPoint.get());
 			checkProvidedMountPoint(customMountPoint);
 			this.mountPoint = customMountPoint;
 			this.createdTemporaryMountPoint = false;

+ 2 - 1
main/ui/src/main/java/org/cryptomator/ui/model/Vault.java

@@ -8,6 +8,7 @@
  *******************************************************************************/
 package org.cryptomator.ui.model;
 
+import com.google.common.base.Strings;
 import javafx.application.Platform;
 import javafx.beans.Observable;
 import javafx.beans.binding.Binding;
@@ -108,7 +109,7 @@ public class Vault {
 	public synchronized void unlock(CharSequence passphrase) throws CryptoException, IOException, Volume.VolumeException {
 		Platform.runLater(() -> state.set(State.PROCESSING));
 		try {
-			if (vaultSettings.usesIndividualMountPath().get() && vaultSettings.individualMountPath().get().isEmpty()) {
+			if (vaultSettings.usesIndividualMountPath().get() && Strings.isNullOrEmpty(vaultSettings.individualMountPath().get())) {
 				throw new NotDirectoryException("");
 			}
 			CryptoFileSystem fs = getCryptoFileSystem(passphrase);