diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java index fff8afc3c..bce307afc 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java @@ -18,7 +18,9 @@ import javax.inject.Inject; import java.io.IOException; import java.nio.file.DirectoryNotEmptyException; import java.nio.file.DirectoryStream; +import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.NotDirectoryException; import java.nio.file.Path; import java.nio.file.Paths; @@ -59,6 +61,18 @@ public class FuseVolume implements Volume { } private void checkProvidedMountPoint(Path mountPoint) throws IOException { + //On Windows the target folder MUST NOT exist... + if (SystemUtils.IS_OS_WINDOWS) { + //We must use #notExists() here because notExists =/= !exists (see docs) + if (Files.notExists(mountPoint, LinkOption.NOFOLLOW_LINKS)) { + //File really doesn't exist + return; + } + //File exists OR can't be determined + throw new FileAlreadyExistsException(mountPoint.toString()); + } + + //... on Mac and Linux it's the opposite if (!Files.isDirectory(mountPoint)) { throw new NotDirectoryException(mountPoint.toString()); } 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 20109f01e..b44a9436b 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 @@ -27,6 +27,7 @@ import javax.inject.Named; import java.io.IOException; import java.nio.CharBuffer; import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileSystemException; import java.nio.file.NotDirectoryException; import java.util.Arrays; @@ -83,7 +84,7 @@ public class UnlockWorkflow extends Task { cancel(false); // set Tasks state to cancelled return false; } - } catch (NotDirectoryException | DirectoryNotEmptyException e) { + } catch (FileAlreadyExistsException | NotDirectoryException | DirectoryNotEmptyException e) { handleInvalidMountPoint(e); throw e; // rethrow to trigger correct exception handling in Task } catch (Exception e) {