diff --git a/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java b/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java
index 5fdb1d91c..a96e4f0bb 100644
--- a/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java
+++ b/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java
@@ -1,9 +1,27 @@
package org.cryptomator.common.mount;
+import java.nio.file.Path;
+
+/**
+ * Indicates that validation or preparation of a mountpoint failed due to a configuration error or an invalid system state.
+ * Instances of this exception are usually caught and displayed to the user in an appropriate fashion, e.g. by {@link org.cryptomator.ui.unlock.UnlockInvalidMountPointController UnlockInvalidMountPointController.}
+ *
+ * @see MountPointPreparationException MountPointPreparationException for wrapping exceptions which occur while preparing the mountpoint.
+ */
public class IllegalMountPointException extends IllegalArgumentException {
- public IllegalMountPointException(String msg) {
- super(msg);
+ private final Path mountpoint;
+
+ public IllegalMountPointException(Path mountpoint) {
+ this(mountpoint, "The provided mountpoint has a problem: " + mountpoint.toString());
}
-}
+ public IllegalMountPointException(Path mountpoint, String msg) {
+ super(msg);
+ this.mountpoint = mountpoint;
+ }
+
+ public Path getMountpoint() {
+ return mountpoint;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java b/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java
index 9f7f11174..d104cff4d 100644
--- a/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java
+++ b/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java
@@ -1,8 +1,10 @@
package org.cryptomator.common.mount;
+import java.nio.file.Path;
+
public class MountPointInUseException extends IllegalMountPointException {
- public MountPointInUseException(String msg) {
- super(msg);
+ public MountPointInUseException(Path path) {
+ super(path);
}
}
diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java
index e90523bc2..677e2fb01 100644
--- a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java
+++ b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java
@@ -1,8 +1,10 @@
package org.cryptomator.common.mount;
+import java.nio.file.Path;
+
public class MountPointNotExistsException extends IllegalMountPointException {
- public MountPointNotExistsException(String msg) {
- super(msg);
+ public MountPointNotExistsException(Path path, String msg) {
+ super(path, msg);
}
}
diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java
index e321f23b1..94e59121c 100644
--- a/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java
+++ b/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java
@@ -1,8 +1,10 @@
package org.cryptomator.common.mount;
+import java.nio.file.Path;
+
public class MountPointNotSupportedException extends IllegalMountPointException {
- public MountPointNotSupportedException(String msg) {
- super(msg);
+ public MountPointNotSupportedException(Path path, String msg) {
+ super(path, msg);
}
}
diff --git a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java
index e4734e011..12a4a1c29 100644
--- a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java
+++ b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java
@@ -1,12 +1,18 @@
package org.cryptomator.common.mount;
+/**
+ * Used for wrapping exceptions which occur while preparing the mountpoint.
+ * Instances of this exception are usually treated as generic error.
+ *
+ * @see IllegalMountPointException IllegalMountPointException for indicating configuration errors.
+ */
public class MountPointPreparationException extends RuntimeException {
- public MountPointPreparationException(String msg) {
- super(msg);
- }
-
public MountPointPreparationException(Throwable cause) {
super(cause);
}
-}
+
+ public MountPointPreparationException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java
index 2aa9feadc..1727d9374 100644
--- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java
+++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java
@@ -5,12 +5,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
-import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.NotDirectoryException;
import java.nio.file.Path;
public final class MountWithinParentUtil {
@@ -22,16 +19,16 @@ public final class MountWithinParentUtil {
private MountWithinParentUtil() {}
- static void prepareParentNoMountPoint(Path mountPoint) throws MountPointPreparationException {
+ static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException {
Path hideaway = getHideaway(mountPoint);
var mpExists = Files.exists(mountPoint, LinkOption.NOFOLLOW_LINKS);
var hideExists = Files.exists(hideaway, LinkOption.NOFOLLOW_LINKS);
//TODO: possible improvement by just deleting an _empty_ hideaway
if (mpExists && hideExists) { //both resources exist (whatever type)
- throw new MountPointPreparationException(new FileAlreadyExistsException(hideaway.toString()));
+ throw new IllegalMountPointException(mountPoint);
} else if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist
- throw new MountPointPreparationException(new NoSuchFileException(mountPoint.toString()));
+ throw new IllegalMountPointException(mountPoint);
} else if (!mpExists) { //only hideaway exists
checkIsDirectory(hideaway);
LOG.info("Mountpoint {} seems to be not properly cleaned up. Will be fixed on unmount.", mountPoint);
@@ -54,7 +51,7 @@ public final class MountWithinParentUtil {
int attempts = 0;
while (!Files.notExists(mountPoint)) {
if (attempts >= 10) {
- throw new MountPointPreparationException("Path " + mountPoint + " could not be cleared");
+ throw new IllegalMountPointException(mountPoint, "Path could not be cleared: " + mountPoint);
}
Thread.sleep(1000);
attempts++;
@@ -99,16 +96,16 @@ public final class MountWithinParentUtil {
}
}
- private static void checkIsDirectory(Path toCheck) throws MountPointPreparationException {
+ private static void checkIsDirectory(Path toCheck) throws IllegalMountPointException {
if (!Files.isDirectory(toCheck, LinkOption.NOFOLLOW_LINKS)) {
- throw new MountPointPreparationException(new NotDirectoryException(toCheck.toString()));
+ throw new IllegalMountPointException(toCheck);
}
}
- private static void checkIsEmpty(Path toCheck) throws MountPointPreparationException, IOException {
+ private static void checkIsEmpty(Path toCheck) throws IllegalMountPointException, IOException {
try (var dirStream = Files.list(toCheck)) {
if (dirStream.findFirst().isPresent()) {
- throw new MountPointPreparationException(new DirectoryNotEmptyException(toCheck.toString()));
+ throw new IllegalMountPointException(toCheck);
}
}
}
diff --git a/src/main/java/org/cryptomator/common/mount/Mounter.java b/src/main/java/org/cryptomator/common/mount/Mounter.java
index 593cb6666..cb89aa50e 100644
--- a/src/main/java/org/cryptomator/common/mount/Mounter.java
+++ b/src/main/java/org/cryptomator/common/mount/Mounter.java
@@ -99,7 +99,7 @@ public class Mounter {
var mpIsDriveLetter = userChosenMountPoint.toString().matches("[A-Z]:\\\\");
if (mpIsDriveLetter) {
if (driveLetters.getOccupied().contains(userChosenMountPoint)) {
- throw new MountPointInUseException(userChosenMountPoint.toString());
+ throw new MountPointInUseException(userChosenMountPoint);
}
} else if (canMountToParent && !canMountToDir) {
MountWithinParentUtil.prepareParentNoMountPoint(userChosenMountPoint);
@@ -115,13 +115,13 @@ public class Mounter {
|| (!canMountToParent && !mpIsDriveLetter) //
|| (!canMountToDir && !canMountToParent && !canMountToSystem && !canMountToDriveLetter);
if (configNotSupported) {
- throw new MountPointNotSupportedException(e.getMessage());
+ throw new MountPointNotSupportedException(userChosenMountPoint, e.getMessage());
} else if (canMountToDir && !canMountToParent && !Files.exists(userChosenMountPoint)) {
//mountpoint must exist
- throw new MountPointNotExistsException(e.getMessage());
+ throw new MountPointNotExistsException(userChosenMountPoint, e.getMessage());
} else {
//TODO: add specific exception for !canMountToDir && canMountToParent && !Files.notExists(userChosenMountPoint)
- throw new IllegalMountPointException(e.getMessage());
+ throw new IllegalMountPointException(userChosenMountPoint, e.getMessage());
}
}
}