check dir structure first in determineVaultState

This commit is contained in:
Jan-Peter Klein
2025-08-27 08:37:04 +02:00
parent 53c6045cca
commit 14c5693594

View File

@@ -186,32 +186,36 @@ public class VaultListManager {
}
public static VaultState.Value determineVaultState(Path pathToVault) throws IOException {
Path pathToVaultConfig = pathToVault.resolve(VAULTCONFIG_FILENAME);
Path pathToMasterkey = pathToVault.resolve(MASTERKEY_FILENAME);
if (!Files.exists(pathToVault)) {
return MISSING;
}
if(!Files.exists(pathToVaultConfig)) {
VaultState.Value structureResult = checkDirStructure(pathToVault);
if (structureResult == LOCKED || structureResult == NEEDS_MIGRATION) {
return structureResult;
}
Path pathToVaultConfig = pathToVault.resolve(VAULTCONFIG_FILENAME);
Path pathToMasterkey = pathToVault.resolve(MASTERKEY_FILENAME);
if (!Files.exists(pathToVaultConfig)) {
BackupRestorer.restoreIfBackupPresent(pathToVault, VAULTCONFIG_FILENAME);
}
if(!Files.exists(pathToMasterkey)){
if (!Files.exists(pathToMasterkey)) {
BackupRestorer.restoreIfBackupPresent(pathToVault, MASTERKEY_FILENAME);
}
if (!Files.exists(pathToVaultConfig) && !Files.exists(pathToMasterkey)) {
boolean hasConfig = Files.exists(pathToVaultConfig);
if (!hasConfig && !Files.exists(pathToMasterkey)) {
return ALL_MISSING;
}
var checkedDirStructureVaultState = checkDirStructure(pathToVault);
if (!Files.exists(pathToVaultConfig)) {
return switch (checkedDirStructureVaultState) {
case LOCKED, MISSING -> VAULT_CONFIG_MISSING;
default -> checkedDirStructureVaultState;
};
if (!hasConfig) {
return VAULT_CONFIG_MISSING;
}
return checkedDirStructureVaultState;
return structureResult;
}
private static VaultState.Value checkDirStructure(Path pathToVault) throws IOException {