From bb0b1b35926771e55832a05a6206abd14dba866f Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:48:46 +0200 Subject: [PATCH] Cleaned up merge --- .../common/mount/ExistingHideawayException.java | 17 ----------------- .../mount/HideawayNotDirectoryException.java | 17 +++++++++++++++++ .../common/mount/MountWithinParentUtil.java | 15 +++++---------- .../UnlockInvalidMountPointController.java | 8 ++++---- src/main/resources/i18n/strings.properties | 2 +- 5 files changed, 27 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java create mode 100644 src/main/java/org/cryptomator/common/mount/HideawayNotDirectoryException.java diff --git a/src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java b/src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java deleted file mode 100644 index aa720d42c..000000000 --- a/src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/common/mount/HideawayNotDirectoryException.java b/src/main/java/org/cryptomator/common/mount/HideawayNotDirectoryException.java new file mode 100644 index 000000000..506f0f10b --- /dev/null +++ b/src/main/java/org/cryptomator/common/mount/HideawayNotDirectoryException.java @@ -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; + } +} \ 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 cabaf6775..38bc437de 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -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 } diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 6e11ed131..8a4fbf304 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -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); diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index d0d770329..dca30a2f9 100644 --- a/src/main/resources/i18n/strings.properties +++ b/src/main/resources/i18n/strings.properties @@ -131,7 +131,7 @@ unlock.error.customPath.message=Unable to mount vault to custom path unlock.error.customPath.description.notSupported=If you wish to keep using the custom path, please go to the preferences and select a volume type that supports it. Otherwise, go to the vault options and choose a supported mount point. unlock.error.customPath.description.notExists=The custom mount path does not exist. Either create it in your local filesystem or change it in the vault options. unlock.error.customPath.description.inUse=Drive letter "%s" is already in use. -unlock.error.customPath.description.hideawayExists=The folder "%3$s", which is used to preserve folder properties set by you, has not been automatically cleaned up since your last mount to "%1$s". Please delete it manually and restore any properties to the original mount path if you set any. +unlock.error.customPath.description.hideawayNotDir=The path "%3$s", which is used to preserve folder properties set by you for your mount path "%1$s", is not a folder. Please delete it manually and restore any properties to the original mount path if you set any. unlock.error.customPath.description.couldNotBeCleaned=Your vault could not be mounted to the path "%s". Please try again or choose a different path. unlock.error.customPath.description.notEmptyDir=The custom mount path "%s" is not an empty folder. Please choose an empty folder and try again. unlock.error.customPath.description.generic=You have selected a custom mount path for this vault, but using it failed with the message: %2$s