From 4110057fa188bc07043ee68c6800a1eac9a4bfaf Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Thu, 13 Aug 2020 19:32:04 +0200 Subject: [PATCH] Refactored multiple classes Refactored UnlockWorkflow, CustomMountPointChooser, DokanyVolume and UnlockInvalidMountPointController Changed UnlockWorkflow#handleGenericError() to accept Throwables Added check for parent to CustomMountPointChooser (when using FUSE on Win) Removed legacy constant from DokanyVolume Added asserts to UnlockInvalidMountPointController and UnlockWorkflow --- .../common/mountpoint/CustomMountPointChooser.java | 4 ++++ .../main/java/org/cryptomator/common/vaults/DokanyVolume.java | 1 - .../ui/unlock/UnlockInvalidMountPointController.java | 1 + .../main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/mountpoint/CustomMountPointChooser.java b/main/commons/src/main/java/org/cryptomator/common/mountpoint/CustomMountPointChooser.java index 3664fd72a..2a69b8cc3 100644 --- a/main/commons/src/main/java/org/cryptomator/common/mountpoint/CustomMountPointChooser.java +++ b/main/commons/src/main/java/org/cryptomator/common/mountpoint/CustomMountPointChooser.java @@ -46,6 +46,10 @@ public class CustomMountPointChooser implements MountPointChooser { //This the case on Windows when using FUSE //See https://github.com/billziss-gh/winfsp/issues/320 + Path parent = mountPoint.getParent(); + if (!Files.isDirectory(parent)) { + throw wrapAsIMPE(new NotDirectoryException(parent.toString())); + } //We must use #notExists() here because notExists =/= !exists (see docs) if (!Files.notExists(mountPoint, LinkOption.NOFOLLOW_LINKS)) { //File exists OR can't be determined diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java index 69ff035de..becd3d7e8 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java @@ -22,7 +22,6 @@ import java.util.concurrent.ExecutorService; public class DokanyVolume implements Volume { private static final Logger LOG = LoggerFactory.getLogger(DokanyVolume.class); - private static final int MAX_TMPMOUNTPOINT_CREATION_RETRIES = 10; private static final String FS_TYPE_NAME = "Cryptomator File System"; diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index b34d62b03..a70f58311 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -40,6 +40,7 @@ public class UnlockInvalidMountPointController implements FxController { public boolean getMustExist() { MountPointRequirement requirement = vault.getMountPointRequirement(); assert requirement != MountPointRequirement.NONE; //An invalid MountPoint with no required MountPoint doesn't seem sensible + assert requirement != MountPointRequirement.PARENT_OPT_MOUNT_POINT; //Not implemented anywhere (yet) return requirement == MountPointRequirement.EMPTY_MOUNT_POINT; } diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 5d8cd6852..829f8f740 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -162,6 +162,7 @@ public class UnlockWorkflow extends Task { private void handleInvalidMountPoint(InvalidMountPointException e) { MountPointRequirement requirement = vault.getMountPointRequirement(); assert requirement != MountPointRequirement.NONE; //An invalid MountPoint with no required MountPoint doesn't seem sensible + assert requirement != MountPointRequirement.PARENT_OPT_MOUNT_POINT; //Not implemented anywhere (yet) if (requirement == MountPointRequirement.EMPTY_MOUNT_POINT) { LOG.error("Unlock failed. Mount point not an empty directory or doesn't exist: {}", e.getMessage()); @@ -174,7 +175,7 @@ public class UnlockWorkflow extends Task { }); } - private void handleGenericError(Exception e) { + private void handleGenericError(Throwable e) { LOG.error("Unlock failed for technical reasons.", e); Platform.runLater(() -> { errorComponent.cause(e).window(window).returnToScene(window.getScene()).build().showErrorScene();