Quellcode durchsuchen

check dir structure first in determineVaultState

Jan-Peter Klein vor 2 Wochen
Ursprung
Commit
14c5693594
1 geänderte Dateien mit 17 neuen und 13 gelöschten Zeilen
  1. 17 13
      src/main/java/org/cryptomator/common/vaults/VaultListManager.java

+ 17 - 13
src/main/java/org/cryptomator/common/vaults/VaultListManager.java

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