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

This commit is contained in:
Jan-Peter Klein
2025-09-01 09:14:21 +02:00
parent d65442f042
commit 8eedc62fbe
2 changed files with 10 additions and 11 deletions

View File

@@ -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");
}

View File

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