Cleaned up merge

This commit is contained in:
JaniruTEC
2023-07-11 20:48:46 +02:00
parent ed6f1ad8d1
commit bb0b1b3592
5 changed files with 27 additions and 32 deletions

View File

@@ -1,17 +0,0 @@
package org.cryptomator.common.mount;
import java.nio.file.Path;
public class ExistingHideawayException extends IllegalMountPointException {
private final Path hideaway;
public ExistingHideawayException(Path path, Path hideaway, String msg) {
super(path, msg);
this.hideaway = hideaway;
}
public Path getHideaway() {
return hideaway;
}
}

View File

@@ -0,0 +1,17 @@
package org.cryptomator.common.mount;
import java.nio.file.Path;
public class HideawayNotDirectoryException extends IllegalMountPointException {
private final Path hideaway;
public HideawayNotDirectoryException(Path path, Path hideaway) {
super(path, "Existing hideaway (" + hideaway.toString() + ") for mountpoint is not a directory: " + path.toString());
this.hideaway = hideaway;
}
public Path getHideaway() {
return hideaway;
}
}

View File

@@ -10,7 +10,6 @@ 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;
import java.nio.file.attribute.BasicFileAttributes;
@@ -28,8 +27,6 @@ public final class MountWithinParentUtil {
var mpExists = removeResidualJunction(mountPoint); //Handle junction as not existing
var hideExists = Files.exists(hideaway, LinkOption.NOFOLLOW_LINKS);
//TODO: possible improvement by just deleting an _empty_ hideaway
//TODO: Remove "ExistingHideawayException"
if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist
throw new MountPointNotExistingException(mountPoint);
} else if (!mpExists) { //only hideaway exists
@@ -45,7 +42,7 @@ public final class MountWithinParentUtil {
} else { //mountpoint exists...
try {
if (hideExists) { //... with hideaway
removeResidualHideaway(hideaway);
removeResidualHideaway(mountPoint, hideaway);
}
//... (now) without hideaway
@@ -73,8 +70,7 @@ public final class MountWithinParentUtil {
}
}
//TODO Remove MountPointPreparationException
private static boolean removeResidualJunction(Path path) throws MountPointPreparationException {
private static boolean removeResidualJunction(Path path) {
try {
if (Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS).isOther()) {
LOG.info("Mountpoint \"{}\" is still a junction. Deleting it.", path);
@@ -85,14 +81,13 @@ public final class MountWithinParentUtil {
} catch (NoSuchFileException e) {
return false;
} catch (IOException e) {
throw new MountPointPreparationException(e);
throw new UncheckedIOException(e);
}
}
//TODO Remove MountPointPreparationException
private static void removeResidualHideaway(Path hideaway) throws IOException {
private static void removeResidualHideaway(Path mountPoint, Path hideaway) throws IOException {
if (!Files.isDirectory(hideaway, LinkOption.NOFOLLOW_LINKS)) {
throw new MountPointPreparationException(new NotDirectoryException(hideaway.toString()));
throw new HideawayNotDirectoryException(mountPoint, hideaway);
}
Files.delete(hideaway); //Fails if not empty
}

View File

@@ -1,6 +1,6 @@
package org.cryptomator.ui.unlock;
import org.cryptomator.common.mount.ExistingHideawayException;
import org.cryptomator.common.mount.HideawayNotDirectoryException;
import org.cryptomator.common.mount.IllegalMountPointException;
import org.cryptomator.common.mount.MountPointCleanupFailedException;
import org.cryptomator.common.mount.MountPointInUseException;
@@ -48,7 +48,7 @@ public class UnlockInvalidMountPointController implements FxController {
this.exceptionType = getExceptionType(exc);
this.exceptionPath = exc.getMountpoint();
this.exceptionMessage = exc.getMessage();
this.hideawayPath = exc instanceof ExistingHideawayException haeExc ? haeExc.getHideaway() : null;
this.hideawayPath = exc instanceof HideawayNotDirectoryException haeExc ? haeExc.getHideaway() : null;
}
@FXML
@@ -81,7 +81,7 @@ public class UnlockInvalidMountPointController implements FxController {
case MountPointNotSupportedException x -> ExceptionType.NOT_SUPPORTED;
case MountPointNotExistingException x -> ExceptionType.NOT_EXISTING;
case MountPointInUseException x -> ExceptionType.IN_USE;
case ExistingHideawayException x -> ExceptionType.HIDEAWAY_EXISTS;
case HideawayNotDirectoryException x -> ExceptionType.HIDEAWAY_NOT_DIR;
case MountPointCleanupFailedException x -> ExceptionType.COULD_NOT_BE_CLEARED;
case MountPointNotEmptyDirectoryException x -> ExceptionType.NOT_EMPTY_DIRECTORY;
default -> ExceptionType.GENERIC;
@@ -93,7 +93,7 @@ public class UnlockInvalidMountPointController implements FxController {
NOT_SUPPORTED("unlock.error.customPath.description.notSupported", ButtonAction.SHOW_PREFERENCES),
NOT_EXISTING("unlock.error.customPath.description.notExists", ButtonAction.SHOW_VAULT_OPTIONS),
IN_USE("unlock.error.customPath.description.inUse", ButtonAction.SHOW_VAULT_OPTIONS),
HIDEAWAY_EXISTS("unlock.error.customPath.description.hideawayExists", ButtonAction.SHOW_VAULT_OPTIONS),
HIDEAWAY_NOT_DIR("unlock.error.customPath.description.hideawayNotDir", ButtonAction.SHOW_VAULT_OPTIONS),
COULD_NOT_BE_CLEARED("unlock.error.customPath.description.couldNotBeCleaned", ButtonAction.SHOW_VAULT_OPTIONS),
NOT_EMPTY_DIRECTORY("unlock.error.customPath.description.notEmptyDir", ButtonAction.SHOW_VAULT_OPTIONS),
GENERIC("unlock.error.customPath.description.generic", ButtonAction.SHOW_PREFERENCES);