Introducing more vault states

This commit is contained in:
Sebastian Stenzel
2019-09-06 10:40:57 +02:00
parent 7de08f52df
commit 9eee7883c5
8 changed files with 60 additions and 7 deletions

View File

@@ -54,7 +54,7 @@ public class Vault {
@Deprecated(forRemoval = true, since = "1.5.0")
public static final Predicate<Vault> NOT_LOCKED = hasState(VaultState.LOCKED).negate();
private static final Logger LOG = LoggerFactory.getLogger(Vault.class);
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator";
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; // TODO: deduplicate constant declared in multiple classes
private static final Path HOME_DIR = Paths.get(SystemUtils.USER_HOME);
private final VaultSettings vaultSettings;

View File

@@ -22,6 +22,9 @@ public interface VaultComponent {
@BindsInstance
Builder vaultSettings(VaultSettings vaultSettings);
@BindsInstance
Builder initialVaultState(VaultState vaultState);
VaultComponent build();
}

View File

@@ -9,14 +9,20 @@
package org.cryptomator.common.vaults;
import org.cryptomator.common.settings.VaultSettings;
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
import org.cryptomator.cryptofs.migration.Migrators;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@Singleton
public class VaultFactory {
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; // TODO: deduplicate constant declared in multiple classes
private final VaultComponent.Builder vaultComponentBuilder;
private final ConcurrentMap<VaultSettings, Vault> vaults = new ConcurrentHashMap<>();
@@ -31,8 +37,23 @@ public class VaultFactory {
}
private Vault create(VaultSettings vaultSettings) {
VaultComponent comp = vaultComponentBuilder.vaultSettings(vaultSettings).build();
VaultState vaultState = determineVaultState(vaultSettings.path().get());
VaultComponent comp = vaultComponentBuilder.vaultSettings(vaultSettings).initialVaultState(vaultState).build();
return comp.vault();
}
private VaultState determineVaultState(Path pathToVault) {
try {
if (!CryptoFileSystemProvider.containsVault(pathToVault, MASTERKEY_FILENAME)) {
return VaultState.MISSING;
} else if (Migrators.get().needsMigration(pathToVault, MASTERKEY_FILENAME)) {
return VaultState.NEEDS_MIGRATION;
} else {
return VaultState.LOCKED;
}
} catch (IOException e) {
return VaultState.ERROR;
}
}
}

View File

@@ -42,8 +42,8 @@ public class VaultModule {
@Provides
@PerVault
public ObjectProperty<VaultState> provideVaultState() {
return new SimpleObjectProperty<>(VaultState.LOCKED);
public ObjectProperty<VaultState> provideVaultState(VaultState initialState) {
return new SimpleObjectProperty<>(initialState);
}
@Provides

View File

@@ -1,6 +1,34 @@
package org.cryptomator.common.vaults;
public enum VaultState {
LOCKED, PROCESSING, UNLOCKED;
/**
* No vault found at the provided path
*/
MISSING,
/**
* Vault requires migration to a newer vault format
*/
NEEDS_MIGRATION,
/**
* Vault ready to be unlocked
*/
LOCKED,
/**
* Vault in transition between two other states
*/
PROCESSING,
/**
* Vault is unlocked
*/
UNLOCKED,
/**
* Unknown state due to preceeding unrecoverable exceptions.
*/
ERROR;
}

View File

@@ -52,7 +52,7 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
public class CreateNewVaultPasswordController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(CreateNewVaultPasswordController.class);
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator";
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; // TODO: deduplicate constant declared in multiple classes
private final Stage window;
private final Lazy<Scene> chooseLocationScene;

View File

@@ -43,7 +43,7 @@ import java.util.Optional;
public class ChangePasswordController implements ViewController {
private static final Logger LOG = LoggerFactory.getLogger(ChangePasswordController.class);
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator";
private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; // TODO: deduplicate constant declared in multiple classes
private final Application app;
private final PasswordStrengthUtil strengthRater;

View File

@@ -24,6 +24,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
@Deprecated(forRemoval = true, since = "1.5.0")
public class DirectoryListCell extends DraggableListCell<Vault> {
private static final Color UNLOCKED_ICON_COLOR = new Color(0.901, 0.494, 0.133, 1.0);