diff --git a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java index 38bc437de..11671e4af 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -30,7 +30,7 @@ public final class MountWithinParentUtil { if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist throw new MountPointNotExistingException(mountPoint); } else if (!mpExists) { //only hideaway exists - checkIsDirectory(hideaway); + checkIsHideawayDirectory(mountPoint, hideaway); LOG.info("Mountpoint {} seems to be not properly cleaned up. Will be fixed on unmount.", mountPoint); try { if (SystemUtils.IS_OS_WINDOWS) { @@ -86,9 +86,7 @@ public final class MountWithinParentUtil { } private static void removeResidualHideaway(Path mountPoint, Path hideaway) throws IOException { - if (!Files.isDirectory(hideaway, LinkOption.NOFOLLOW_LINKS)) { - throw new HideawayNotDirectoryException(mountPoint, hideaway); - } + checkIsHideawayDirectory(mountPoint, hideaway); Files.delete(hideaway); //Fails if not empty } @@ -134,6 +132,12 @@ public final class MountWithinParentUtil { } } + private static void checkIsHideawayDirectory(Path mountPoint, Path hideawayToCheck) { + if (!Files.isDirectory(hideawayToCheck, LinkOption.NOFOLLOW_LINKS)) { + throw new HideawayNotDirectoryException(mountPoint, hideawayToCheck); + } + } + private static void checkIsEmpty(Path toCheck) throws IllegalMountPointException, IOException { try (var dirStream = Files.list(toCheck)) { if (dirStream.findFirst().isPresent()) {