From 58c7774e0da628eb188b9b8c33c4502da82639be Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:50:52 +0200 Subject: [PATCH 01/10] Added arg3 to FormattedLabel --- .../ui/controls/FormattedLabel.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/controls/FormattedLabel.java b/src/main/java/org/cryptomator/ui/controls/FormattedLabel.java index 04ed7e477..4c0883cba 100644 --- a/src/main/java/org/cryptomator/ui/controls/FormattedLabel.java +++ b/src/main/java/org/cryptomator/ui/controls/FormattedLabel.java @@ -13,18 +13,19 @@ public class FormattedLabel extends Label { private final StringProperty format = new SimpleStringProperty(""); private final ObjectProperty arg1 = new SimpleObjectProperty<>(); private final ObjectProperty arg2 = new SimpleObjectProperty<>(); - // add arg2, arg3, ... on demand + private final ObjectProperty arg3 = new SimpleObjectProperty<>(); + // add arg4, arg5, ... on demand public FormattedLabel() { textProperty().bind(createStringBinding()); } protected StringBinding createStringBinding() { - return Bindings.createStringBinding(this::updateText, format, arg1, arg2); + return Bindings.createStringBinding(this::updateText, format, arg1, arg2, arg3); } private String updateText() { - return String.format(format.get(), arg1.get(), arg2.get()); + return String.format(format.get(), arg1.get(), arg2.get(), arg3.get()); } /* Observables */ @@ -64,4 +65,16 @@ public class FormattedLabel extends Label { public void setArg2(Object arg2) { this.arg2.set(arg2); } + + public ObjectProperty arg3Property() { + return arg3; + } + + public Object getArg3() { + return arg3.get(); + } + + public void setArg3(Object arg3) { + this.arg3.set(arg3); + } } From 12f5f41968b897878a3169cd47b3f0d0b0fb3bfc Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:28:40 +0200 Subject: [PATCH 02/10] Redefined IllegalMountPointException and MountPointPreparationException --- .../mount/IllegalMountPointException.java | 24 ++++++++++++++++--- .../mount/MountPointInUseException.java | 6 +++-- .../mount/MountPointNotExistsException.java | 6 +++-- .../MountPointNotSupportedException.java | 6 +++-- .../mount/MountPointPreparationException.java | 16 +++++++++---- .../common/mount/MountWithinParentUtil.java | 19 +++++++-------- .../org/cryptomator/common/mount/Mounter.java | 8 +++---- 7 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java b/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java index 5fdb1d91c..a96e4f0bb 100644 --- a/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java +++ b/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java @@ -1,9 +1,27 @@ package org.cryptomator.common.mount; +import java.nio.file.Path; + +/** + * Indicates that validation or preparation of a mountpoint failed due to a configuration error or an invalid system state.
+ * Instances of this exception are usually caught and displayed to the user in an appropriate fashion, e.g. by {@link org.cryptomator.ui.unlock.UnlockInvalidMountPointController UnlockInvalidMountPointController.} + * + * @see MountPointPreparationException MountPointPreparationException for wrapping exceptions which occur while preparing the mountpoint. + */ public class IllegalMountPointException extends IllegalArgumentException { - public IllegalMountPointException(String msg) { - super(msg); + private final Path mountpoint; + + public IllegalMountPointException(Path mountpoint) { + this(mountpoint, "The provided mountpoint has a problem: " + mountpoint.toString()); } -} + public IllegalMountPointException(Path mountpoint, String msg) { + super(msg); + this.mountpoint = mountpoint; + } + + public Path getMountpoint() { + return mountpoint; + } +} \ No newline at end of file diff --git a/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java b/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java index 9f7f11174..d104cff4d 100644 --- a/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java +++ b/src/main/java/org/cryptomator/common/mount/MountPointInUseException.java @@ -1,8 +1,10 @@ package org.cryptomator.common.mount; +import java.nio.file.Path; + public class MountPointInUseException extends IllegalMountPointException { - public MountPointInUseException(String msg) { - super(msg); + public MountPointInUseException(Path path) { + super(path); } } diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java index e90523bc2..677e2fb01 100644 --- a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java +++ b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java @@ -1,8 +1,10 @@ package org.cryptomator.common.mount; +import java.nio.file.Path; + public class MountPointNotExistsException extends IllegalMountPointException { - public MountPointNotExistsException(String msg) { - super(msg); + public MountPointNotExistsException(Path path, String msg) { + super(path, msg); } } diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java index e321f23b1..94e59121c 100644 --- a/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java +++ b/src/main/java/org/cryptomator/common/mount/MountPointNotSupportedException.java @@ -1,8 +1,10 @@ package org.cryptomator.common.mount; +import java.nio.file.Path; + public class MountPointNotSupportedException extends IllegalMountPointException { - public MountPointNotSupportedException(String msg) { - super(msg); + public MountPointNotSupportedException(Path path, String msg) { + super(path, msg); } } diff --git a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java index e4734e011..12a4a1c29 100644 --- a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java +++ b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java @@ -1,12 +1,18 @@ package org.cryptomator.common.mount; +/** + * Used for wrapping exceptions which occur while preparing the mountpoint.
+ * Instances of this exception are usually treated as generic error. + * + * @see IllegalMountPointException IllegalMountPointException for indicating configuration errors. + */ public class MountPointPreparationException extends RuntimeException { - public MountPointPreparationException(String msg) { - super(msg); - } - public MountPointPreparationException(Throwable cause) { super(cause); } -} + + public MountPointPreparationException(String msg, Throwable cause) { + super(msg, cause); + } +} \ 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 2aa9feadc..1727d9374 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -5,12 +5,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.file.DirectoryNotEmptyException; 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; public final class MountWithinParentUtil { @@ -22,16 +19,16 @@ public final class MountWithinParentUtil { private MountWithinParentUtil() {} - static void prepareParentNoMountPoint(Path mountPoint) throws MountPointPreparationException { + static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException { 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 MountPointPreparationException(new FileAlreadyExistsException(hideaway.toString())); + throw new IllegalMountPointException(mountPoint); } else if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist - throw new MountPointPreparationException(new NoSuchFileException(mountPoint.toString())); + throw new IllegalMountPointException(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); @@ -54,7 +51,7 @@ public final class MountWithinParentUtil { int attempts = 0; while (!Files.notExists(mountPoint)) { if (attempts >= 10) { - throw new MountPointPreparationException("Path " + mountPoint + " could not be cleared"); + throw new IllegalMountPointException(mountPoint, "Path could not be cleared: " + mountPoint); } Thread.sleep(1000); attempts++; @@ -99,16 +96,16 @@ public final class MountWithinParentUtil { } } - private static void checkIsDirectory(Path toCheck) throws MountPointPreparationException { + private static void checkIsDirectory(Path toCheck) throws IllegalMountPointException { if (!Files.isDirectory(toCheck, LinkOption.NOFOLLOW_LINKS)) { - throw new MountPointPreparationException(new NotDirectoryException(toCheck.toString())); + throw new IllegalMountPointException(toCheck); } } - private static void checkIsEmpty(Path toCheck) throws MountPointPreparationException, IOException { + private static void checkIsEmpty(Path toCheck) throws IllegalMountPointException, IOException { try (var dirStream = Files.list(toCheck)) { if (dirStream.findFirst().isPresent()) { - throw new MountPointPreparationException(new DirectoryNotEmptyException(toCheck.toString())); + throw new IllegalMountPointException(toCheck); } } } diff --git a/src/main/java/org/cryptomator/common/mount/Mounter.java b/src/main/java/org/cryptomator/common/mount/Mounter.java index 593cb6666..cb89aa50e 100644 --- a/src/main/java/org/cryptomator/common/mount/Mounter.java +++ b/src/main/java/org/cryptomator/common/mount/Mounter.java @@ -99,7 +99,7 @@ public class Mounter { var mpIsDriveLetter = userChosenMountPoint.toString().matches("[A-Z]:\\\\"); if (mpIsDriveLetter) { if (driveLetters.getOccupied().contains(userChosenMountPoint)) { - throw new MountPointInUseException(userChosenMountPoint.toString()); + throw new MountPointInUseException(userChosenMountPoint); } } else if (canMountToParent && !canMountToDir) { MountWithinParentUtil.prepareParentNoMountPoint(userChosenMountPoint); @@ -115,13 +115,13 @@ public class Mounter { || (!canMountToParent && !mpIsDriveLetter) // || (!canMountToDir && !canMountToParent && !canMountToSystem && !canMountToDriveLetter); if (configNotSupported) { - throw new MountPointNotSupportedException(e.getMessage()); + throw new MountPointNotSupportedException(userChosenMountPoint, e.getMessage()); } else if (canMountToDir && !canMountToParent && !Files.exists(userChosenMountPoint)) { //mountpoint must exist - throw new MountPointNotExistsException(e.getMessage()); + throw new MountPointNotExistsException(userChosenMountPoint, e.getMessage()); } else { //TODO: add specific exception for !canMountToDir && canMountToParent && !Files.notExists(userChosenMountPoint) - throw new IllegalMountPointException(e.getMessage()); + throw new IllegalMountPointException(userChosenMountPoint, e.getMessage()); } } } From 08a1e1ec7d1d0e70900d4ab3620263fdf153dc36 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 03/10] Added/Refactored exceptions to account for more cases --- .../common/mount/HideawayAlreadyExistsException.java | 10 ++++++++++ .../mount/MountPointCouldNotBeClearedException.java | 10 ++++++++++ .../mount/MountPointNotEmptyDirectoryException.java | 10 ++++++++++ .../common/mount/MountPointNotExistsException.java | 4 ++++ .../common/mount/MountWithinParentUtil.java | 12 ++++++------ 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java create mode 100644 src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java create mode 100644 src/main/java/org/cryptomator/common/mount/MountPointNotEmptyDirectoryException.java 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); } } } From becc5e316a5e8e95c214d2e9421c5bb8ac095023 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:00:33 +0200 Subject: [PATCH 04/10] Made interaction between Unlock logic & UI more consistent --- .../ui/unlock/UnlockInvalidMountPointController.java | 5 +++-- src/main/java/org/cryptomator/ui/unlock/UnlockModule.java | 3 ++- .../java/org/cryptomator/ui/unlock/UnlockWorkflow.java | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 83bd80df4..1af21a5e0 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.unlock; +import org.cryptomator.common.mount.IllegalMountPointException; import org.cryptomator.common.mount.MountPointInUseException; import org.cryptomator.common.mount.MountPointNotExistsException; import org.cryptomator.common.mount.MountPointNotSupportedException; @@ -30,13 +31,13 @@ public class UnlockInvalidMountPointController implements FxController { public FormattedLabel dialogDescription; @Inject - UnlockInvalidMountPointController(@UnlockWindow Stage window, @UnlockWindow Vault vault, @UnlockWindow AtomicReference unlockException, FxApplicationWindows appWindows, ResourceBundle resourceBundle) { + UnlockInvalidMountPointController(@UnlockWindow Stage window, @UnlockWindow Vault vault, @UnlockWindow AtomicReference illegalMountPointException, FxApplicationWindows appWindows, ResourceBundle resourceBundle) { this.window = window; this.vault = vault; this.appWindows = appWindows; this.resourceBundle = resourceBundle; - var exc = unlockException.get(); + var exc = illegalMountPointException.get(); this.exceptionType = getExceptionType(exc); this.exceptionMessage = exc.getMessage(); } diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java b/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java index b59fa272d..c84c12db1 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockModule.java @@ -4,6 +4,7 @@ import dagger.Binds; import dagger.Module; import dagger.Provides; import dagger.multibindings.IntoMap; +import org.cryptomator.common.mount.IllegalMountPointException; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.DefaultSceneFactory; import org.cryptomator.ui.common.FxController; @@ -61,7 +62,7 @@ abstract class UnlockModule { @Provides @UnlockWindow @UnlockScoped - static AtomicReference unlockException() { + static AtomicReference illegalMountPointException() { return new AtomicReference<>(); } diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index cd4f5fcba..ea91a3651 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -40,10 +40,10 @@ public class UnlockWorkflow extends Task { private final Lazy invalidMountPointScene; private final FxApplicationWindows appWindows; private final KeyLoadingStrategy keyLoadingStrategy; - private final AtomicReference unlockFailedException; + private final AtomicReference illegalMountPointException; @Inject - UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, FxApplicationWindows appWindows, @UnlockWindow KeyLoadingStrategy keyLoadingStrategy, @UnlockWindow AtomicReference unlockFailedException) { + UnlockWorkflow(@UnlockWindow Stage window, @UnlockWindow Vault vault, VaultService vaultService, @FxmlScene(FxmlFile.UNLOCK_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.UNLOCK_INVALID_MOUNT_POINT) Lazy invalidMountPointScene, FxApplicationWindows appWindows, @UnlockWindow KeyLoadingStrategy keyLoadingStrategy, @UnlockWindow AtomicReference illegalMountPointException) { this.window = window; this.vault = vault; this.vaultService = vaultService; @@ -51,7 +51,7 @@ public class UnlockWorkflow extends Task { this.invalidMountPointScene = invalidMountPointScene; this.appWindows = appWindows; this.keyLoadingStrategy = keyLoadingStrategy; - this.unlockFailedException = unlockFailedException; + this.illegalMountPointException = illegalMountPointException; } @Override @@ -79,7 +79,7 @@ public class UnlockWorkflow extends Task { private void handleIllegalMountPointError(IllegalMountPointException impe) { Platform.runLater(() -> { - unlockFailedException.set(impe); + illegalMountPointException.set(impe); window.setScene(invalidMountPointScene.get()); window.show(); }); From 9361a75cd88a6c6393c9c9d8561dc29d796f13c3 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:21:16 +0200 Subject: [PATCH 05/10] Refactored UnlockInvalidMountPointController to use improved Exceptions --- .../ui/unlock/UnlockInvalidMountPointController.java | 6 +++++- src/main/resources/i18n/strings.properties | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 1af21a5e0..22812ec0f 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -14,6 +14,7 @@ import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab; import javax.inject.Inject; import javafx.fxml.FXML; import javafx.stage.Stage; +import java.nio.file.Path; import java.util.ResourceBundle; import java.util.concurrent.atomic.AtomicReference; @@ -26,6 +27,7 @@ public class UnlockInvalidMountPointController implements FxController { private final FxApplicationWindows appWindows; private final ResourceBundle resourceBundle; private final ExceptionType exceptionType; + private final Path exceptionPath; private final String exceptionMessage; public FormattedLabel dialogDescription; @@ -39,13 +41,15 @@ public class UnlockInvalidMountPointController implements FxController { var exc = illegalMountPointException.get(); this.exceptionType = getExceptionType(exc); + this.exceptionPath = exc.getMountpoint(); this.exceptionMessage = exc.getMessage(); } @FXML public void initialize() { dialogDescription.setFormat(resourceBundle.getString(exceptionType.translationKey)); - dialogDescription.setArg1(exceptionMessage); + dialogDescription.setArg1(exceptionPath); + dialogDescription.setArg2(exceptionMessage); } @FXML diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index ca051269a..a9942eb51 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.generic=You have selected a custom mount path for this vault, but using it failed with the message: %s +unlock.error.customPath.description.generic=You have selected a custom mount path for this vault, but using it failed with the message: %2$s ## Hub hub.noKeychain.message=Unable to access device key hub.noKeychain.description=In order to unlock Hub vaults, a device key is required, which is secured using a keychain. To proceed, enable ā€œ%sā€ and select a keychain in the preferences. From 2a9d1e3fba8d118475e2df9fbd87a6063e983450 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 22:33:27 +0200 Subject: [PATCH 06/10] Added messages for MountPointCouldNotBeClearedException and MountPointNotEmptyDirectoryException --- .../ui/unlock/UnlockInvalidMountPointController.java | 6 ++++++ src/main/resources/i18n/strings.properties | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 22812ec0f..509df30dd 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -1,7 +1,9 @@ package org.cryptomator.ui.unlock; import org.cryptomator.common.mount.IllegalMountPointException; +import org.cryptomator.common.mount.MountPointCouldNotBeClearedException; import org.cryptomator.common.mount.MountPointInUseException; +import org.cryptomator.common.mount.MountPointNotEmptyDirectoryException; import org.cryptomator.common.mount.MountPointNotExistsException; import org.cryptomator.common.mount.MountPointNotSupportedException; import org.cryptomator.common.vaults.Vault; @@ -74,6 +76,8 @@ public class UnlockInvalidMountPointController implements FxController { case MountPointNotSupportedException x -> ExceptionType.NOT_SUPPORTED; case MountPointNotExistsException x -> ExceptionType.NOT_EXISTING; case MountPointInUseException x -> ExceptionType.IN_USE; + case MountPointCouldNotBeClearedException x -> ExceptionType.COULD_NOT_BE_CLEARED; + case MountPointNotEmptyDirectoryException x -> ExceptionType.NOT_EMPTY_DIRECTORY; default -> ExceptionType.GENERIC; }; } @@ -83,6 +87,8 @@ 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), + 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); private final String translationKey; diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index a9942eb51..730609137 100644 --- a/src/main/resources/i18n/strings.properties +++ b/src/main/resources/i18n/strings.properties @@ -131,6 +131,8 @@ 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.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 ## Hub hub.noKeychain.message=Unable to access device key From 614756c7408f511bea4d92ac265538c85c68b1ae Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Tue, 11 Jul 2023 22:35:08 +0200 Subject: [PATCH 07/10] Added message for HideawayAlreadyExistsException --- .../common/mount/HideawayAlreadyExistsException.java | 9 ++++++++- .../cryptomator/common/mount/MountWithinParentUtil.java | 2 +- .../ui/unlock/UnlockInvalidMountPointController.java | 7 +++++++ src/main/resources/i18n/strings.properties | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java b/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java index 57f255b2e..b2a938b1c 100644 --- a/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java +++ b/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java @@ -4,7 +4,14 @@ import java.nio.file.Path; public class HideawayAlreadyExistsException extends IllegalMountPointException { - public HideawayAlreadyExistsException(Path path, String msg) { + private final Path hideaway; + + public HideawayAlreadyExistsException(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/MountWithinParentUtil.java b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java index 4c829d68d..1ee1b37cf 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -26,7 +26,7 @@ public final class MountWithinParentUtil { //TODO: possible improvement by just deleting an _empty_ hideaway if (mpExists && hideExists) { //both resources exist (whatever type) - throw new HideawayAlreadyExistsException(mountPoint, "Hideaway (" + hideaway + ") already exists for mountpoint: " + mountPoint); + throw new HideawayAlreadyExistsException(mountPoint, hideaway, "Hideaway (" + hideaway + ") already exists for mountpoint: " + mountPoint); } else if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist throw new MountPointNotExistsException(mountPoint); } else if (!mpExists) { //only hideaway exists diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 509df30dd..37ae85b9b 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.unlock; +import org.cryptomator.common.mount.HideawayAlreadyExistsException; import org.cryptomator.common.mount.IllegalMountPointException; import org.cryptomator.common.mount.MountPointCouldNotBeClearedException; import org.cryptomator.common.mount.MountPointInUseException; @@ -31,6 +32,7 @@ public class UnlockInvalidMountPointController implements FxController { private final ExceptionType exceptionType; private final Path exceptionPath; private final String exceptionMessage; + private final Path hideawayPath; public FormattedLabel dialogDescription; @@ -45,6 +47,7 @@ public class UnlockInvalidMountPointController implements FxController { this.exceptionType = getExceptionType(exc); this.exceptionPath = exc.getMountpoint(); this.exceptionMessage = exc.getMessage(); + this.hideawayPath = exc instanceof HideawayAlreadyExistsException haeExc ? haeExc.getHideaway() : null; } @FXML @@ -52,6 +55,7 @@ public class UnlockInvalidMountPointController implements FxController { dialogDescription.setFormat(resourceBundle.getString(exceptionType.translationKey)); dialogDescription.setArg1(exceptionPath); dialogDescription.setArg2(exceptionMessage); + dialogDescription.setArg3(hideawayPath); } @FXML @@ -76,6 +80,7 @@ public class UnlockInvalidMountPointController implements FxController { case MountPointNotSupportedException x -> ExceptionType.NOT_SUPPORTED; case MountPointNotExistsException x -> ExceptionType.NOT_EXISTING; case MountPointInUseException x -> ExceptionType.IN_USE; + case HideawayAlreadyExistsException x -> ExceptionType.HIDEAWAY_EXISTS; case MountPointCouldNotBeClearedException x -> ExceptionType.COULD_NOT_BE_CLEARED; case MountPointNotEmptyDirectoryException x -> ExceptionType.NOT_EMPTY_DIRECTORY; default -> ExceptionType.GENERIC; @@ -87,6 +92,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), 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); @@ -102,6 +108,7 @@ public class UnlockInvalidMountPointController implements FxController { private enum ButtonAction { + //TODO Add option to show filesystem, e.g. for ExceptionType.HIDEAWAY_EXISTS SHOW_PREFERENCES, SHOW_VAULT_OPTIONS; diff --git a/src/main/resources/i18n/strings.properties b/src/main/resources/i18n/strings.properties index 730609137..d0d770329 100644 --- a/src/main/resources/i18n/strings.properties +++ b/src/main/resources/i18n/strings.properties @@ -131,6 +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.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 From aa2e63acb0f86e9b036585cdca0c2884cbf4ec18 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:58:56 +0200 Subject: [PATCH 08/10] Added `@PropertyKey` See: https://github.com/cryptomator/cryptomator/pull/3001#discussion_r1263039593 --- .../ui/unlock/UnlockInvalidMountPointController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 37ae85b9b..9144f0a74 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -13,6 +13,7 @@ import org.cryptomator.ui.controls.FormattedLabel; import org.cryptomator.ui.fxapp.FxApplicationWindows; import org.cryptomator.ui.preferences.SelectedPreferencesTab; import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab; +import org.jetbrains.annotations.PropertyKey; import javax.inject.Inject; import javafx.fxml.FXML; @@ -100,7 +101,7 @@ public class UnlockInvalidMountPointController implements FxController { private final String translationKey; private final ButtonAction action; - ExceptionType(String translationKey, ButtonAction action) { + ExceptionType(@PropertyKey(resourceBundle = "i18n.strings") String translationKey, ButtonAction action) { this.translationKey = translationKey; this.action = action; } From a90e75ceba86d41d2dcedc094dc321de29273720 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:09:36 +0200 Subject: [PATCH 09/10] Renamed exceptions See: https://github.com/cryptomator/cryptomator/pull/3001#discussion_r1263563166 --- ...ception.java => ExistingHideawayException.java} | 4 ++-- .../mount/MountPointCleanupFailedException.java | 10 ++++++++++ .../MountPointCouldNotBeClearedException.java | 10 ---------- .../mount/MountPointNotExistingException.java | 14 ++++++++++++++ .../common/mount/MountPointNotExistsException.java | 14 -------------- .../common/mount/MountWithinParentUtil.java | 6 +++--- .../java/org/cryptomator/common/mount/Mounter.java | 2 +- .../unlock/UnlockInvalidMountPointController.java | 14 +++++++------- 8 files changed, 37 insertions(+), 37 deletions(-) rename src/main/java/org/cryptomator/common/mount/{HideawayAlreadyExistsException.java => ExistingHideawayException.java} (55%) create mode 100644 src/main/java/org/cryptomator/common/mount/MountPointCleanupFailedException.java delete mode 100644 src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java create mode 100644 src/main/java/org/cryptomator/common/mount/MountPointNotExistingException.java delete mode 100644 src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java diff --git a/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java b/src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java similarity index 55% rename from src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java rename to src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java index b2a938b1c..aa720d42c 100644 --- a/src/main/java/org/cryptomator/common/mount/HideawayAlreadyExistsException.java +++ b/src/main/java/org/cryptomator/common/mount/ExistingHideawayException.java @@ -2,11 +2,11 @@ package org.cryptomator.common.mount; import java.nio.file.Path; -public class HideawayAlreadyExistsException extends IllegalMountPointException { +public class ExistingHideawayException extends IllegalMountPointException { private final Path hideaway; - public HideawayAlreadyExistsException(Path path, Path hideaway, String msg) { + public ExistingHideawayException(Path path, Path hideaway, String msg) { super(path, msg); this.hideaway = hideaway; } diff --git a/src/main/java/org/cryptomator/common/mount/MountPointCleanupFailedException.java b/src/main/java/org/cryptomator/common/mount/MountPointCleanupFailedException.java new file mode 100644 index 000000000..6246e124c --- /dev/null +++ b/src/main/java/org/cryptomator/common/mount/MountPointCleanupFailedException.java @@ -0,0 +1,10 @@ +package org.cryptomator.common.mount; + +import java.nio.file.Path; + +public class MountPointCleanupFailedException extends IllegalMountPointException { + + public MountPointCleanupFailedException(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/MountPointCouldNotBeClearedException.java b/src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java deleted file mode 100644 index 03150176c..000000000 --- a/src/main/java/org/cryptomator/common/mount/MountPointCouldNotBeClearedException.java +++ /dev/null @@ -1,10 +0,0 @@ -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/MountPointNotExistingException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotExistingException.java new file mode 100644 index 000000000..bebf63ee3 --- /dev/null +++ b/src/main/java/org/cryptomator/common/mount/MountPointNotExistingException.java @@ -0,0 +1,14 @@ +package org.cryptomator.common.mount; + +import java.nio.file.Path; + +public class MountPointNotExistingException extends IllegalMountPointException { + + public MountPointNotExistingException(Path path, String msg) { + super(path, msg); + } + + public MountPointNotExistingException(Path path) { + super(path, "Mountpoint does not exist: " + path); + } +} diff --git a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java b/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java deleted file mode 100644 index f1c41b0b7..000000000 --- a/src/main/java/org/cryptomator/common/mount/MountPointNotExistsException.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.cryptomator.common.mount; - -import java.nio.file.Path; - -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 1ee1b37cf..e7a703e43 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -26,9 +26,9 @@ public final class MountWithinParentUtil { //TODO: possible improvement by just deleting an _empty_ hideaway if (mpExists && hideExists) { //both resources exist (whatever type) - throw new HideawayAlreadyExistsException(mountPoint, hideaway, "Hideaway (" + hideaway + ") already exists for mountpoint: " + mountPoint); + throw new ExistingHideawayException(mountPoint, hideaway, "Hideaway (" + hideaway + ") already exists for mountpoint: " + mountPoint); } else if (!mpExists && !hideExists) { //neither mountpoint nor hideaway exist - throw new MountPointNotExistsException(mountPoint); + throw new MountPointNotExistingException(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 MountPointCouldNotBeClearedException(mountPoint); + throw new MountPointCleanupFailedException(mountPoint); } Thread.sleep(1000); attempts++; diff --git a/src/main/java/org/cryptomator/common/mount/Mounter.java b/src/main/java/org/cryptomator/common/mount/Mounter.java index cb89aa50e..101524ea3 100644 --- a/src/main/java/org/cryptomator/common/mount/Mounter.java +++ b/src/main/java/org/cryptomator/common/mount/Mounter.java @@ -118,7 +118,7 @@ public class Mounter { throw new MountPointNotSupportedException(userChosenMountPoint, e.getMessage()); } else if (canMountToDir && !canMountToParent && !Files.exists(userChosenMountPoint)) { //mountpoint must exist - throw new MountPointNotExistsException(userChosenMountPoint, e.getMessage()); + throw new MountPointNotExistingException(userChosenMountPoint, e.getMessage()); } else { //TODO: add specific exception for !canMountToDir && canMountToParent && !Files.notExists(userChosenMountPoint) throw new IllegalMountPointException(userChosenMountPoint, e.getMessage()); diff --git a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java index 9144f0a74..6e11ed131 100644 --- a/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java +++ b/src/main/java/org/cryptomator/ui/unlock/UnlockInvalidMountPointController.java @@ -1,11 +1,11 @@ package org.cryptomator.ui.unlock; -import org.cryptomator.common.mount.HideawayAlreadyExistsException; +import org.cryptomator.common.mount.ExistingHideawayException; import org.cryptomator.common.mount.IllegalMountPointException; -import org.cryptomator.common.mount.MountPointCouldNotBeClearedException; +import org.cryptomator.common.mount.MountPointCleanupFailedException; import org.cryptomator.common.mount.MountPointInUseException; import org.cryptomator.common.mount.MountPointNotEmptyDirectoryException; -import org.cryptomator.common.mount.MountPointNotExistsException; +import org.cryptomator.common.mount.MountPointNotExistingException; import org.cryptomator.common.mount.MountPointNotSupportedException; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; @@ -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 HideawayAlreadyExistsException haeExc ? haeExc.getHideaway() : null; + this.hideawayPath = exc instanceof ExistingHideawayException haeExc ? haeExc.getHideaway() : null; } @FXML @@ -79,10 +79,10 @@ public class UnlockInvalidMountPointController implements FxController { private ExceptionType getExceptionType(Throwable unlockException) { return switch (unlockException) { case MountPointNotSupportedException x -> ExceptionType.NOT_SUPPORTED; - case MountPointNotExistsException x -> ExceptionType.NOT_EXISTING; + case MountPointNotExistingException x -> ExceptionType.NOT_EXISTING; case MountPointInUseException x -> ExceptionType.IN_USE; - case HideawayAlreadyExistsException x -> ExceptionType.HIDEAWAY_EXISTS; - case MountPointCouldNotBeClearedException x -> ExceptionType.COULD_NOT_BE_CLEARED; + case ExistingHideawayException x -> ExceptionType.HIDEAWAY_EXISTS; + case MountPointCleanupFailedException x -> ExceptionType.COULD_NOT_BE_CLEARED; case MountPointNotEmptyDirectoryException x -> ExceptionType.NOT_EMPTY_DIRECTORY; default -> ExceptionType.GENERIC; }; From c3ac043c68d4add2c2ef687f34b541219cca81e2 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Fri, 14 Jul 2023 21:13:11 +0200 Subject: [PATCH 10/10] Removed MountPointPreparationException See: https://github.com/cryptomator/cryptomator/pull/3001#discussion_r1263572178 --- .../mount/IllegalMountPointException.java | 2 -- .../mount/MountPointPreparationException.java | 18 ------------------ .../common/mount/MountWithinParentUtil.java | 9 +++++---- 3 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java diff --git a/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java b/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java index a96e4f0bb..30419d85c 100644 --- a/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java +++ b/src/main/java/org/cryptomator/common/mount/IllegalMountPointException.java @@ -5,8 +5,6 @@ import java.nio.file.Path; /** * Indicates that validation or preparation of a mountpoint failed due to a configuration error or an invalid system state.
* Instances of this exception are usually caught and displayed to the user in an appropriate fashion, e.g. by {@link org.cryptomator.ui.unlock.UnlockInvalidMountPointController UnlockInvalidMountPointController.} - * - * @see MountPointPreparationException MountPointPreparationException for wrapping exceptions which occur while preparing the mountpoint. */ public class IllegalMountPointException extends IllegalArgumentException { diff --git a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java b/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java deleted file mode 100644 index 12a4a1c29..000000000 --- a/src/main/java/org/cryptomator/common/mount/MountPointPreparationException.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.cryptomator.common.mount; - -/** - * Used for wrapping exceptions which occur while preparing the mountpoint.
- * Instances of this exception are usually treated as generic error. - * - * @see IllegalMountPointException IllegalMountPointException for indicating configuration errors. - */ -public class MountPointPreparationException extends RuntimeException { - - public MountPointPreparationException(Throwable cause) { - super(cause); - } - - public MountPointPreparationException(String msg, Throwable cause) { - super(msg, cause); - } -} \ 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 e7a703e43..64f382e02 100644 --- a/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java +++ b/src/main/java/org/cryptomator/common/mount/MountWithinParentUtil.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.LinkOption; @@ -19,7 +20,7 @@ public final class MountWithinParentUtil { private MountWithinParentUtil() {} - static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException, MountPointPreparationException { + static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException { Path hideaway = getHideaway(mountPoint); var mpExists = Files.exists(mountPoint, LinkOption.NOFOLLOW_LINKS); var hideExists = Files.exists(hideaway, LinkOption.NOFOLLOW_LINKS); @@ -37,7 +38,7 @@ public final class MountWithinParentUtil { Files.setAttribute(hideaway, WIN_HIDDEN_ATTR, true, LinkOption.NOFOLLOW_LINKS); } } catch (IOException e) { - throw new MountPointPreparationException(e); + throw new UncheckedIOException(e); } } else { //only mountpoint exists try { @@ -57,10 +58,10 @@ public final class MountWithinParentUtil { attempts++; } } catch (IOException e) { - throw new MountPointPreparationException(e); + throw new UncheckedIOException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MountPointPreparationException(e); + throw new RuntimeException(e); } } }