Bläddra i källkod

Check vault path before preparing new vault in recovery flow and refactor chooseValidVaultDirectory() to return Path instead of File

Jan-Peter Klein 5 dagar sedan
förälder
incheckning
8eedc62fbe

+ 4 - 5
src/main/java/org/cryptomator/common/recovery/VaultPreparator.java

@@ -23,12 +23,11 @@ public final class VaultPreparator {
 
 	private VaultPreparator() {}
 
-	public static Vault prepareVault(File selectedDirectory, VaultComponent.Factory vaultComponentFactory, List<MountService> mountServices) {
-		Path selectedPath = selectedDirectory.toPath();
+	public static Vault prepareVault(Path selectedDirectory, VaultComponent.Factory vaultComponentFactory, List<MountService> mountServices) {
 		VaultSettings vaultSettings = VaultSettings.withRandomId();
-		vaultSettings.path.set(selectedPath);
-		if (selectedPath.getFileName() != null) {
-			vaultSettings.displayName.set(selectedPath.getFileName().toString());
+		vaultSettings.path.set(selectedDirectory);
+		if (selectedDirectory.getFileName() != null) {
+			vaultSettings.displayName.set(selectedDirectory.getFileName().toString());
 		} else {
 			vaultSettings.displayName.set("defaultVaultName");
 		}

+ 6 - 6
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java

@@ -226,7 +226,7 @@ public class VaultListController implements FxController {
 		VaultListManager.redetermineVaultState(newValue);
 	}
 
-	private Optional<File> chooseValidVaultDirectory() {
+	private Optional<Path> chooseValidVaultDirectory() {
 		DirectoryChooser directoryChooser = new DirectoryChooser();
 		File selectedDirectory;
 
@@ -243,7 +243,7 @@ public class VaultListController implements FxController {
 			}
 		} while (selectedDirectory == null);
 
-		return Optional.of(selectedDirectory);
+		return Optional.of(selectedDirectory.toPath());
 	}
 
 	@FXML
@@ -258,14 +258,13 @@ public class VaultListController implements FxController {
 
 	@FXML
 	public void didClickRecoverExistingVault() {
-		Optional<File> selectedDirectory = chooseValidVaultDirectory();
+		Optional<Path> selectedDirectory = chooseValidVaultDirectory();
 		if (selectedDirectory.isEmpty()) {
 			return;
 		}
 
-		Vault preparedVault = VaultPreparator.prepareVault(selectedDirectory.get(), vaultComponentFactory, mountServices);
-
-		Optional<Vault> matchingVaultListEntry = vaultListManager.get(preparedVault.getPath());
+		Path path = selectedDirectory.get();
+		Optional<Vault> matchingVaultListEntry = vaultListManager.get(path);
 		if (matchingVaultListEntry.isPresent()) {
 			dialogs.prepareRecoveryVaultAlreadyExists(mainWindow, matchingVaultListEntry.get().getDisplayName()) //
 					.setOkAction(Stage::close) //
@@ -273,6 +272,7 @@ public class VaultListController implements FxController {
 			return;
 		}
 
+		Vault preparedVault = VaultPreparator.prepareVault(path, vaultComponentFactory, mountServices);
 		VaultListManager.redetermineVaultState(preparedVault);
 
 		switch (preparedVault.getState()) {