diff --git a/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java b/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java new file mode 100644 index 000000000..57f255b2e --- /dev/null +++ b/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java @@ -0,0 +1,10 @@ +package org.cryptomator.common.mount; + +import java.nio.file.Path; + +public class HideawayAlreadyExistsException extends IllegalMountPointException { + + public HideawayAlreadyExistsException(Path path, String msg) { + super(path, msg); + } +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java b/src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java new file mode 100644 index 000000000..03150176c --- /dev/null +++ b/src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java @@ -0,0 +1,10 @@ +package org.cryptomator.common.mount; + +import java.nio.file.Path; + +public class MountPointCouldNotBeClearedException extends IllegalMountPointException { + + public MountPointCouldNotBeClearedException(Path path) { + super(path, "Mountpoint could not be cleared: " + path.toString()); + } +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotEmptyDirectoryException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotEmptyDirectoryException.java new file mode 100644 index 000000000..79801613f --- /dev/null +++ b/src/main/java/org/cryptomator/common/mount/MountPointNotEmptyDirectoryException.java @@ -0,0 +1,10 @@ +package org.cryptomator.common.mount; + +import java.nio.file.Path; + +public class MountPointNotEmptyDirectoryException extends IllegalMountPointException { + + public MountPointNotEmptyDirectoryException(Path path, String msg) { + super(path, msg); + } +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java index 677e2fb01..f1c41b0b7 100644 --- a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java +++ b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java @@ -7,4 +7,8 @@ public class MountPointNotExistsException extends IllegalMountPointException { public MountPointNotExistsException(Path path, String msg) { super(path, msg); } + + public MountPointNotExistsException(Path path) { + super(path, "Mountpoint does not exist: " + path); + } } diff --git a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java index 1727d9374..4c829d68d 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -19,16 +19,16 @@ public final class MountWithinParentUtil { private MountWithinParentUtil() {} - static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException { + static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException, MountPointPreparationException { 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 IllegalMountPointException(mountPoint); + throw new HideawayAlreadyExistsException(mountPoint, "Hideaway (" + hideaway + ") already exists for mountpoint: " + mountPoint); } else if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist - throw new IllegalMountPointException(mountPoint); + throw new MountPointNotExistsException(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); @@ -51,7 +51,7 @@ public final class MountWithinParentUtil { int attempts = 0; while (!Files.notExists(mountPoint)) { if (attempts >= 10) { - throw new IllegalMountPointException(mountPoint, "Path could not be cleared: " + mountPoint); + throw new MountPointCouldNotBeClearedException(mountPoint); } Thread.sleep(1000); attempts++; @@ -98,14 +98,14 @@ public final class MountWithinParentUtil { private static void checkIsDirectory(Path toCheck) throws IllegalMountPointException { if (!Files.isDirectory(toCheck, LinkOption.NOFOLLOW_LINKS)) { - throw new IllegalMountPointException(toCheck); + throw new MountPointNotEmptyDirectoryException(toCheck, "Mountpoint is not a directory: " + toCheck); } } private static void checkIsEmpty(Path toCheck) throws IllegalMountPointException, IOException { try (var dirStream = Files.list(toCheck)) { if (dirStream.findFirst().isPresent()) { - throw new IllegalMountPointException(toCheck); + throw new MountPointNotEmptyDirectoryException(toCheck, "Mountpoint directory is not empty: " + toCheck); } } }