diff --git a/src/main/java/org/cryptomator/common/CommonsModule.java b/src/main/java/org/cryptomator/common/CommonsModule.java index 4ac07495e..76dfb92ed 100644 --- a/src/main/java/org/cryptomator/common/CommonsModule.java +++ b/src/main/java/org/cryptomator/common/CommonsModule.java @@ -5,7 +5,6 @@ *******************************************************************************/ package org.cryptomator.common; -import com.tobiasdiez.easybind.EasyBind; import dagger.Module; import dagger.Provides; import org.apache.commons.lang3.SystemUtils; @@ -16,6 +15,7 @@ import org.cryptomator.common.settings.SettingsProvider; import org.cryptomator.common.vaults.VaultComponent; import org.cryptomator.common.vaults.VaultListModule; import org.cryptomator.cryptolib.common.MasterkeyFileAccess; +import org.cryptomator.integrations.mount.MountService; import org.cryptomator.integrations.revealpath.RevealPathService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +33,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; @Module(subcomponents = {VaultComponent.class}, includes = {VaultListModule.class, KeychainModule.class, MountModule.class}) public abstract class CommonsModule { @@ -145,4 +146,11 @@ public abstract class CommonsModule { }); } + @Provides + @Singleton + @Named("FUPFMS") + static AtomicReference provideFirstUsedProblematicFuseMountService() { + return new AtomicReference<>(null); + } + } diff --git a/src/main/java/org/cryptomator/common/mount/MountModule.java b/src/main/java/org/cryptomator/common/mount/MountModule.java index 5e448a680..74997c096 100644 --- a/src/main/java/org/cryptomator/common/mount/MountModule.java +++ b/src/main/java/org/cryptomator/common/mount/MountModule.java @@ -4,10 +4,8 @@ import dagger.Module; import dagger.Provides; import org.cryptomator.integrations.mount.MountService; -import javax.inject.Named; import javax.inject.Singleton; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; @Module public class MountModule { @@ -18,10 +16,4 @@ public class MountModule { return MountService.get().toList(); } - @Provides - @Singleton - @Named("FUPFMS") - static AtomicReference provideFirstUsedProblematicFuseMountService() { - return new AtomicReference<>(null); - } } diff --git a/src/main/java/org/cryptomator/common/vaults/Vault.java b/src/main/java/org/cryptomator/common/vaults/Vault.java index 6cc86bb8a..8da676d33 100644 --- a/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -10,6 +10,7 @@ package org.cryptomator.common.vaults; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.Constants; +import org.cryptomator.common.ObservableUtil; import org.cryptomator.common.mount.ActualMountService; import org.cryptomator.common.mount.Mounter; import org.cryptomator.common.mount.WindowsDriveLetters; @@ -23,6 +24,7 @@ import org.cryptomator.cryptolib.api.CryptoException; import org.cryptomator.cryptolib.api.MasterkeyLoader; import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException; import org.cryptomator.integrations.mount.MountFailedException; +import org.cryptomator.integrations.mount.MountService; import org.cryptomator.integrations.mount.Mountpoint; import org.cryptomator.integrations.mount.UnmountFailedException; import org.slf4j.Logger; @@ -44,6 +46,7 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.EnumSet; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; @@ -72,11 +75,14 @@ public class Vault { private final Mounter mounter; private final BooleanProperty showingStats; private final ObservableValue actualMountService; + private final List mountProviders; + private final ObservableValue selectedMountService; + private final AtomicReference firstUsedProblematicFuseMountService; private final AtomicReference mountHandle = new AtomicReference<>(null); @Inject - Vault(VaultSettings vaultSettings, VaultConfigCache configCache, AtomicReference cryptoFileSystem, VaultState state, @Named("lastKnownException") ObjectProperty lastKnownException, VaultStats stats, WindowsDriveLetters windowsDriveLetters, Mounter mounter, @Named("vaultMountService") ObservableValue actualMountService) { + Vault(VaultSettings vaultSettings, VaultConfigCache configCache, AtomicReference cryptoFileSystem, List mountProviders, VaultState state, @Named("lastKnownException") ObjectProperty lastKnownException, VaultStats stats, WindowsDriveLetters windowsDriveLetters, Mounter mounter, @Named("vaultMountService") ObservableValue actualMountService, @Named("FUPFMS") AtomicReference firstUsedProblematicFuseMountService) { this.vaultSettings = vaultSettings; this.configCache = configCache; this.cryptoFileSystem = cryptoFileSystem; @@ -94,6 +100,10 @@ public class Vault { this.mounter = mounter; this.showingStats = new SimpleBooleanProperty(false); this.actualMountService = actualMountService; + this.mountProviders = mountProviders; + var fallbackProvider = mountProviders.stream().findFirst().orElse(null); + this.selectedMountService = ObservableUtil.mapWithDefault(vaultSettings.mountService, serviceName -> mountProviders.stream().filter(s -> s.getClass().getName().equals(serviceName)).findFirst().orElse(fallbackProvider), fallbackProvider); + this.firstUsedProblematicFuseMountService = firstUsedProblematicFuseMountService; } // ****************************************************************************** @@ -146,6 +156,16 @@ public class Vault { if (cryptoFileSystem.get() != null) { throw new IllegalStateException("Already unlocked."); } + var fallbackProvider = mountProviders.stream().findFirst().orElse(null); + var selMountServ = ObservableUtil.mapWithDefault(vaultSettings.mountService, serviceName -> mountProviders.stream().filter(s -> s.getClass().getName().equals(serviceName)).findFirst().orElse(fallbackProvider), fallbackProvider); + var fuseRestartRequired = selMountServ.map(s -> // + firstUsedProblematicFuseMountService.get() != null // + && VaultModule.isProblematicFuseService(s) // + && !firstUsedProblematicFuseMountService.get().equals(s)).getValue(); + if(fuseRestartRequired){ + throw new MountFailedException("fuseRestartRequired"); + } + CryptoFileSystem fs = createCryptoFileSystem(keyLoader); boolean success = false; try {