From 8374599183ffe77d76784675290c6d074ea71efe Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Sun, 26 Jul 2020 23:02:26 +0200 Subject: [PATCH] Modified creation of temporary mountpoint, fixed bugs, added comments Changed FuseVolume#prepareTemporaryMountPoint to handle FUSE on Windows correctly (WinFSP requires the folder to NOT exist...) See: https://github.com/billziss-gh/winfsp/issues/320 Added comments Fixed bug: Message showing a malformed path --- .../org/cryptomator/common/vaults/FuseVolume.java | 14 +++++++++++--- .../org/cryptomator/common/vaults/VaultModule.java | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java index e944d5fd6..f94548666 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java @@ -15,6 +15,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; +import java.io.File; import java.io.IOException; import java.nio.file.DirectoryNotEmptyException; import java.nio.file.DirectoryStream; @@ -30,7 +31,6 @@ public class FuseVolume implements Volume { private static final Logger LOG = LoggerFactory.getLogger(FuseVolume.class); private static final int MAX_TMPMOUNTPOINT_CREATION_RETRIES = 10; - private static final boolean IS_MAC = System.getProperty("os.name").toLowerCase().contains("mac"); private final VaultSettings vaultSettings; private final Environment environment; @@ -62,6 +62,7 @@ public class FuseVolume implements Volume { private void checkProvidedMountPoint(Path mountPoint) throws IOException { //On Windows the target folder MUST NOT exist... + //https://github.com/billziss-gh/winfsp/issues/320 if (SystemUtils.IS_OS_WINDOWS) { //We must use #notExists() here because notExists =/= !exists (see docs) if (Files.notExists(mountPoint, LinkOption.NOFOLLOW_LINKS)) { @@ -88,7 +89,14 @@ public class FuseVolume implements Volume { // https://github.com/osxfuse/osxfuse/issues/306#issuecomment-245114592: // In order to allow non-admin users to mount FUSE volumes in `/Volumes`, // starting with version 3.5.0, FUSE will create non-existent mount points automatically. - if (!(IS_MAC && mountPoint.getParent().equals(Paths.get("/Volumes")))) { + if (SystemUtils.IS_OS_MAC && mountPoint.getParent().equals(Paths.get("/Volumes"))) { + return mountPoint; + } + + //WinFSP needs the parent, but the acutal Mount Point must not exist... + if (SystemUtils.IS_OS_WINDOWS) { + Files.createDirectories(mountPoint.getParent()); + } else { Files.createDirectories(mountPoint); this.createdTemporaryMountPoint = true; } @@ -104,7 +112,7 @@ public class FuseVolume implements Volume { return mountPoint; } } - LOG.error("Failed to find feasible mountpoint at {}/{}_x. Giving up after {} attempts.", parent, basename, MAX_TMPMOUNTPOINT_CREATION_RETRIES); + LOG.error("Failed to find feasible mountpoint at {}{}{}_x. Giving up after {} attempts.", parent, File.separator, basename, MAX_TMPMOUNTPOINT_CREATION_RETRIES); throw new VolumeException("Did not find feasible mount point."); } diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultModule.java b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultModule.java index 3631230ff..caf347602 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultModule.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultModule.java @@ -155,12 +155,15 @@ public class VaultModule { //WinFSP has no explicit "readonly"-option, nut not setting the group/user-id has the same effect, tho. //So for the time being not setting them is the way to go... + //See: https://github.com/billziss-gh/winfsp/issues/319 if (!readOnly.get()) { flags.append(" -ouid=-1"); flags.append(" -ogid=-1"); } flags.append(" -ovolname=").append(mountName.get()); - flags.append(" -oThreadCount=").append(5); + //Dokany requires this option to be set, WinFSP doesn't seem to share this peculiarity, + //but the option exists. Let's keep this here in case we need it. +// flags.append(" -oThreadCount=").append(5); return flags.toString().strip(); }