mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 10:41:26 +00:00
Refine impl:
* rename wrapper to cache * reset the cache to null if error during config loading happens * always set the the cache in the vault obj
This commit is contained in:
@@ -58,7 +58,7 @@ public class Vault {
|
||||
private final AtomicReference<CryptoFileSystem> cryptoFileSystem;
|
||||
private final VaultState state;
|
||||
private final ObjectProperty<Exception> lastKnownException;
|
||||
private final VaultConfigWrapper configWrapper;
|
||||
private final VaultConfigCache configWrapper;
|
||||
private final VaultStats stats;
|
||||
private final StringBinding displayName;
|
||||
private final StringBinding displayablePath;
|
||||
@@ -75,7 +75,7 @@ public class Vault {
|
||||
private volatile Volume volume;
|
||||
|
||||
@Inject
|
||||
Vault(VaultSettings vaultSettings, VaultConfigWrapper configWrapper, Provider<Volume> volumeProvider, @DefaultMountFlags StringBinding defaultMountFlags, AtomicReference<CryptoFileSystem> cryptoFileSystem, VaultState state, @Named("lastKnownException") ObjectProperty<Exception> lastKnownException, VaultStats stats) {
|
||||
Vault(VaultSettings vaultSettings, VaultConfigCache configWrapper, Provider<Volume> volumeProvider, @DefaultMountFlags StringBinding defaultMountFlags, AtomicReference<CryptoFileSystem> cryptoFileSystem, VaultState state, @Named("lastKnownException") ObjectProperty<Exception> lastKnownException, VaultStats stats) {
|
||||
this.vaultSettings = vaultSettings;
|
||||
this.configWrapper = configWrapper;
|
||||
this.volumeProvider = volumeProvider;
|
||||
@@ -368,7 +368,7 @@ public class Vault {
|
||||
try {
|
||||
return configWrapper.getConfig();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("One should not accquire the config if thee is not present.");
|
||||
throw new IllegalStateException("Vault Config not present.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import dagger.Subcomponent;
|
||||
import org.cryptomator.common.Nullable;
|
||||
import org.cryptomator.common.mountpoint.MountPointChooserModule;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.cryptofs.VaultConfig;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
@@ -27,7 +26,7 @@ public interface VaultComponent {
|
||||
Builder vaultSettings(VaultSettings vaultSettings);
|
||||
|
||||
@BindsInstance
|
||||
Builder vaultConfigWrapper(VaultConfigWrapper rapper);
|
||||
Builder vaultConfigCache(VaultConfigCache configCache);
|
||||
|
||||
@BindsInstance
|
||||
Builder initialVaultState(VaultState.Value vaultState);
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.cryptofs.VaultConfig;
|
||||
import org.cryptomator.cryptofs.VaultConfigLoadException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import java.io.IOException;
|
||||
@@ -17,18 +16,23 @@ import java.util.Objects;
|
||||
/**
|
||||
* Wrapper for lazy loading and on-demand reloading of the vault configuration.
|
||||
*/
|
||||
public class VaultConfigWrapper {
|
||||
public class VaultConfigCache {
|
||||
|
||||
private final VaultSettings settings;
|
||||
private final ObjectProperty<VaultConfig.UnverifiedVaultConfig> config;
|
||||
|
||||
VaultConfigWrapper(VaultSettings settings) {
|
||||
VaultConfigCache(VaultSettings settings) {
|
||||
this.settings = settings;
|
||||
this.config = new SimpleObjectProperty<>();
|
||||
}
|
||||
|
||||
void reloadConfig() throws IOException {
|
||||
config.set(readConfigFromStorage(this.settings.path().get()));
|
||||
try {
|
||||
config.set(readConfigFromStorage(this.settings.path().get()));
|
||||
} catch (IOException e) {
|
||||
config.set(null);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
VaultConfig.UnverifiedVaultConfig getConfig() throws IOException {
|
||||
@@ -12,7 +12,6 @@ import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.common.settings.VaultSettings;
|
||||
import org.cryptomator.cryptofs.CryptoFileSystemProvider;
|
||||
import org.cryptomator.cryptofs.DirStructure;
|
||||
import org.cryptomator.cryptofs.VaultConfig;
|
||||
import org.cryptomator.cryptofs.migration.Migrators;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -97,9 +96,9 @@ public class VaultListManager {
|
||||
VaultComponent.Builder compBuilder = vaultComponentBuilder.vaultSettings(vaultSettings);
|
||||
try {
|
||||
VaultState.Value vaultState = determineVaultState(vaultSettings.path().get());
|
||||
if (vaultState == LOCKED) {
|
||||
VaultConfigWrapper wrapper = new VaultConfigWrapper(vaultSettings);
|
||||
compBuilder.vaultConfigWrapper(wrapper); //first set the wrapper in the builder, THEN try to load config
|
||||
VaultConfigCache wrapper = new VaultConfigCache(vaultSettings);
|
||||
compBuilder.vaultConfigCache(wrapper); //first set the wrapper in the builder, THEN try to load config
|
||||
if (vaultState == LOCKED) { //for legacy reasons: pre v8 vault do not have a config, but they are in the NEEDS_MIGRATION state
|
||||
wrapper.reloadConfig();
|
||||
}
|
||||
compBuilder.initialVaultState(vaultState);
|
||||
|
||||
Reference in New Issue
Block a user