소스 검색

modified mounter to utilize the mount service settings specified in the vault settings

Jan-Peter Klein 1 년 전
부모
커밋
07906fbea5

+ 4 - 7
src/main/java/org/cryptomator/common/mount/Mounter.java

@@ -27,14 +27,12 @@ public class Mounter {
 	private final Settings settings;
 	private final Environment env;
 	private final WindowsDriveLetters driveLetters;
-	private final ObservableValue<ActualMountService> mountServiceObservable;
 
 	@Inject
-	public Mounter(Settings settings, Environment env, WindowsDriveLetters driveLetters, ObservableValue<ActualMountService> mountServiceObservable) {
+	public Mounter(Settings settings, Environment env, WindowsDriveLetters driveLetters) {
 		this.settings = settings;
 		this.env = env;
 		this.driveLetters = driveLetters;
-		this.mountServiceObservable = mountServiceObservable;
 	}
 
 	private class SettledMounter {
@@ -53,8 +51,7 @@ public class Mounter {
 			for (var capability : service.capabilities()) {
 				switch (capability) {
 					case FILE_SYSTEM_NAME -> builder.setFileSystemName("cryptoFs");
-					case LOOPBACK_PORT ->
-							builder.setLoopbackPort(settings.port.get()); //TODO: move port from settings to vaultsettings (see https://github.com/cryptomator/cryptomator/tree/feature/mount-setting-per-vault)
+					case LOOPBACK_PORT -> builder.setLoopbackPort(vaultSettings.port.get());
 					case LOOPBACK_HOST_NAME -> env.getLoopbackAlias().ifPresent(builder::setLoopbackHostName);
 					case READ_ONLY -> builder.setReadOnly(vaultSettings.usesReadOnlyMode.get());
 					case MOUNT_FLAGS -> {
@@ -130,8 +127,8 @@ public class Mounter {
 
 	}
 
-	public MountHandle mount(VaultSettings vaultSettings, Path cryptoFsRoot) throws IOException, MountFailedException {
-		var mountService = this.mountServiceObservable.getValue().service();
+	public MountHandle mount(VaultSettings vaultSettings, Path cryptoFsRoot, ObservableValue<ActualMountService> actualMountService) throws IOException, MountFailedException {
+		var mountService = actualMountService.getValue().service();
 		var builder = mountService.forFileSystem(cryptoFsRoot);
 		var internal = new SettledMounter(mountService, builder, vaultSettings);
 		var cleanup = internal.prepare();

+ 6 - 2
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.mount.ActualMountService;
 import org.cryptomator.common.mount.Mounter;
 import org.cryptomator.common.mount.WindowsDriveLetters;
 import org.cryptomator.common.settings.VaultSettings;
@@ -38,6 +39,7 @@ import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.ReadOnlyStringProperty;
 import javafx.beans.property.SimpleBooleanProperty;
+import javafx.beans.value.ObservableValue;
 import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -69,11 +71,12 @@ public class Vault {
 	private final ObjectBinding<Mountpoint> mountPoint;
 	private final Mounter mounter;
 	private final BooleanProperty showingStats;
+	private final ObservableValue<ActualMountService> actualMountService;
 
 	private final AtomicReference<Mounter.MountHandle> mountHandle = new AtomicReference<>(null);
 
 	@Inject
-	Vault(VaultSettings vaultSettings, VaultConfigCache configCache, AtomicReference<CryptoFileSystem> cryptoFileSystem, VaultState state, @Named("lastKnownException") ObjectProperty<Exception> lastKnownException, VaultStats stats, WindowsDriveLetters windowsDriveLetters, Mounter mounter) {
+	Vault(VaultSettings vaultSettings, VaultConfigCache configCache, AtomicReference<CryptoFileSystem> cryptoFileSystem, VaultState state, @Named("lastKnownException") ObjectProperty<Exception> lastKnownException, VaultStats stats, WindowsDriveLetters windowsDriveLetters, Mounter mounter, @Named("vaultMountService") ObservableValue<ActualMountService> actualMountService) {
 		this.vaultSettings = vaultSettings;
 		this.configCache = configCache;
 		this.cryptoFileSystem = cryptoFileSystem;
@@ -90,6 +93,7 @@ public class Vault {
 		this.mountPoint = Bindings.createObjectBinding(this::getMountPoint, state);
 		this.mounter = mounter;
 		this.showingStats = new SimpleBooleanProperty(false);
+		this.actualMountService = actualMountService;
 	}
 
 	// ******************************************************************************
@@ -147,7 +151,7 @@ public class Vault {
 		try {
 			cryptoFileSystem.set(fs);
 			var rootPath = fs.getRootDirectories().iterator().next();
-			var mountHandle = mounter.mount(vaultSettings, rootPath);
+			var mountHandle = mounter.mount(vaultSettings, rootPath, actualMountService);
 			success = this.mountHandle.compareAndSet(null, mountHandle);
 		} finally {
 			if (!success) {

+ 26 - 0
src/main/java/org/cryptomator/common/vaults/VaultModule.java

@@ -8,13 +8,19 @@ package org.cryptomator.common.vaults;
 import dagger.Module;
 import dagger.Provides;
 import org.cryptomator.common.Nullable;
+import org.cryptomator.common.ObservableUtil;
+import org.cryptomator.common.mount.ActualMountService;
+import org.cryptomator.common.settings.VaultSettings;
 import org.cryptomator.cryptofs.CryptoFileSystem;
+import org.cryptomator.integrations.mount.MountService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Named;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ObservableValue;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
 @Module
@@ -28,6 +34,26 @@ public class VaultModule {
 		return new AtomicReference<>();
 	}
 
+	@Provides
+	@Named("vaultMountService")
+	@PerVault
+	static ObservableValue<ActualMountService> provideMountService(VaultSettings vaultSettings, List<MountService> serviceImpls, @Named("FUPFMS") AtomicReference<MountService> fupfms) {
+		var fallbackProvider = serviceImpls.stream().findFirst().orElse(null);
+
+		LOG.debug("fallbackProvider.displayName:" + fallbackProvider.displayName());
+
+		var observableMountService = ObservableUtil.mapWithDefault(vaultSettings.mountService, //
+				desiredServiceImpl -> { //
+					var serviceFromSettings = serviceImpls.stream().filter(serviceImpl -> serviceImpl.getClass().getName().equals(desiredServiceImpl)).findAny(); //
+					var targetedService = serviceFromSettings.orElse(fallbackProvider);
+					return new ActualMountService(targetedService,false);//return applyWorkaroundForProblematicFuse(targetedService, serviceFromSettings.isPresent(), fupfms);
+				}, //
+				() -> { //
+					return new ActualMountService(fallbackProvider,false);//return applyWorkaroundForProblematicFuse(fallbackProvider, true, fupfms);
+				});
+		return observableMountService;
+	}
+
 	@Provides
 	@Named("lastKnownException")
 	@PerVault