From 39f9da16f98919de21b17859273a47fa8ea0d683 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Thu, 21 Feb 2019 14:03:52 +0100 Subject: [PATCH] mount path is now configurable via -Dcryptomator.mountPointsDir and no longer hardcoded to ~/.Cryptomator or ~/Library/Application\ Support/Cryptomator fixes #710 --- .../main/java/org/cryptomator/common/Environment.java | 5 +++++ .../java/org/cryptomator/ui/model/FuseVolume.java | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/Environment.java b/main/commons/src/main/java/org/cryptomator/common/Environment.java index 033698f01..16cb14aca 100644 --- a/main/commons/src/main/java/org/cryptomator/common/Environment.java +++ b/main/commons/src/main/java/org/cryptomator/common/Environment.java @@ -31,6 +31,7 @@ public class Environment { LOG.debug("cryptomator.ipcPortPath: {}", System.getProperty("cryptomator.ipcPortPath")); LOG.debug("cryptomator.keychainPath: {}", System.getProperty("cryptomator.keychainPath")); LOG.debug("cryptomator.logDir: {}", System.getProperty("cryptomator.logDir")); + LOG.debug("cryptomator.mountPointsDir: {}", System.getProperty("cryptomator.mountPointsDir")); } public Stream getSettingsPath() { @@ -51,6 +52,10 @@ public class Environment { .map(ABSOLUTE_HOME_DIR::resolve); // resolve relative path against HOME } + public Optional getMountPointsDir() { + return getPath("cryptomator.mountPointsDir").map(this::replaceHomeDir); + } + private Optional getPath(String propertyName) { String value = System.getProperty(propertyName); diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java b/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java index b1d07894b..71868066f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/FuseVolume.java @@ -1,6 +1,7 @@ package org.cryptomator.ui.model; import org.apache.commons.lang3.SystemUtils; +import org.cryptomator.common.Environment; import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.cryptofs.CryptoFileSystem; import org.cryptomator.frontend.fuse.mount.CommandFailedException; @@ -25,21 +26,19 @@ import java.util.Optional; public class FuseVolume implements Volume { private static final Logger LOG = LoggerFactory.getLogger(FuseVolume.class); - - // TODO: dont use fixed Strings and rather set them in some system environment variables in the cryptomator installer and load those! - private static final String DEFAULT_MOUNTROOTPATH_MAC = System.getProperty("user.home") + "/Library/Application Support/Cryptomator"; - private static final String DEFAULT_MOUNTROOTPATH_LINUX = System.getProperty("user.home") + "/.Cryptomator"; private static final int MAX_TMPMOUNTPOINT_CREATION_RETRIES = 10; private final VaultSettings vaultSettings; + private final Environment environment; private Mount fuseMnt; private Path mountPoint; private boolean createdTemporaryMountPoint; @Inject - public FuseVolume(VaultSettings vaultSettings) { + public FuseVolume(VaultSettings vaultSettings, Environment environment) { this.vaultSettings = vaultSettings; + this.environment = environment; } @Override @@ -71,7 +70,7 @@ public class FuseVolume implements Volume { } private Path createTemporaryMountPoint() throws IOException { - Path parent = Paths.get(SystemUtils.IS_OS_MAC ? DEFAULT_MOUNTROOTPATH_MAC : DEFAULT_MOUNTROOTPATH_LINUX); + Path parent = environment.getMountPointsDir().orElseThrow(); String basename = vaultSettings.getId(); for (int i = 0; i < MAX_TMPMOUNTPOINT_CREATION_RETRIES; i++) { try {