Fixed thrown exception

This commit is contained in:
JaniruTEC
2023-07-19 14:04:15 +02:00
parent bb0b1b3592
commit 3ea6da3c6d

View File

@@ -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()) {