implementing the per-vault mount-directory-creation and just removing the id from the volume name

This commit is contained in:
infeo
2018-03-23 17:05:15 +01:00
parent 2d6d3084b0
commit e257d8e497
3 changed files with 55 additions and 32 deletions

View File

@@ -28,7 +28,7 @@
<cryptomator.cryptofs.version>1.5.0-SNAPSHOT</cryptomator.cryptofs.version>
<cryptomator.webdav.version>1.0.4</cryptomator.webdav.version>
<cryptomator.jni.version>2.0.0</cryptomator.jni.version>
<cryptomator.fuse.version>0.1.1</cryptomator.fuse.version>
<cryptomator.fuse.version>0.1.2</cryptomator.fuse.version>
<commons-io.version>2.5</commons-io.version>
<commons-lang3.version>3.6</commons-lang3.version>

View File

@@ -6,17 +6,25 @@ import org.cryptomator.cryptofs.CryptoFileSystem;
import org.cryptomator.frontend.fuse.mount.EnvironmentVariables;
import org.cryptomator.frontend.fuse.mount.FuseMount;
import org.cryptomator.frontend.fuse.mount.MountFactory;
import org.cryptomator.frontend.fuse.mount.FuseMountFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@VaultModule.PerVault
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";
@@ -25,19 +33,49 @@ public class FuseVolume implements Volume {
private final WindowsDriveLetters windowsDriveLetters;
private CryptoFileSystem cfs;
private Path mountPath;
private boolean extraDirCreated;
@Inject
public FuseVolume(VaultSettings vaultSettings, WindowsDriveLetters windowsDriveLetters) {
this.vaultSettings = vaultSettings;
this.windowsDriveLetters = windowsDriveLetters;
this.fuseMnt = MountFactory.createMountObject();
this.fuseMnt = FuseMountFactory.createMountObject();
this.extraDirCreated = false;
}
@Override
public void prepare(CryptoFileSystem fs) {
public void prepare(CryptoFileSystem fs) throws IOException {
this.cfs = fs;
if (!(vaultSettings.individualMountPath().isNotNull().get() || SystemUtils.IS_OS_WINDOWS)) {
fuseMnt.useExtraMountDir();
String mountPath;
if (SystemUtils.IS_OS_WINDOWS) {
//windows case
if (vaultSettings.winDriveLetter().get() != null) {
// specific drive letter selected
mountPath = vaultSettings.winDriveLetter().get() + ":\\";
} else {
// auto assign drive letter
mountPath = windowsDriveLetters.getAvailableDriveLetters().iterator().next() + ":\\";
}
} else if (vaultSettings.individualMountPath().get() != null) {
//specific path given
mountPath = vaultSettings.individualMountPath().get();
} else {
//choose default path & create extra directory
mountPath = createDirIfNotExist(SystemUtils.IS_OS_MAC ? DEFAULT_MOUNTROOTPATH_MAC : DEFAULT_MOUNTROOTPATH_LINUX,
vaultSettings.mountName().get());
extraDirCreated = true;
}
this.mountPath = Paths.get(mountPath).toAbsolutePath();
}
private String createDirIfNotExist(String prefix, String dirName) throws IOException {
Path p = Paths.get(prefix, dirName + vaultSettings.getId());
if (Files.isDirectory(p) && !Files.newDirectoryStream(p).iterator().hasNext()) {
throw new DirectoryNotEmptyException("Mount point is not empty.");
} else {
Files.createDirectory(p);
return p.toString();
}
}
@@ -45,8 +83,8 @@ public class FuseVolume implements Volume {
public void mount() throws CommandFailedException {
try {
EnvironmentVariables envVars = EnvironmentVariables.create()
.withMountName(vaultSettings.mountName().getValue() + "_ID-" + vaultSettings.getId())
.withMountPath(chooseMountRootPath())
.withMountName(vaultSettings.mountName().getValue())
.withMountPath(mountPath.toString())
.build();
fuseMnt.mount(cfs.getPath("/"), envVars);
} catch (Exception e) {
@@ -54,25 +92,6 @@ public class FuseVolume implements Volume {
}
}
private String chooseMountRootPath() {
if (SystemUtils.IS_OS_WINDOWS) {
//windows case
if (vaultSettings.winDriveLetter().get() != null) {
// specific drive letter selected
return vaultSettings.winDriveLetter().getValue() + ":\\";
} else {
// auto assign drive letter selected
return windowsDriveLetters.getAvailableDriveLetters().iterator().next() + ":\\";
}
} else if (vaultSettings.individualMountPath().isNotNull().get()) {
//specific path given
return vaultSettings.individualMountPath().getValue();
} else {
//choose default path
return SystemUtils.IS_OS_MAC ? DEFAULT_MOUNTROOTPATH_MAC : DEFAULT_MOUNTROOTPATH_LINUX;
}
}
@Override
public void reveal() throws CommandFailedException {
try {
@@ -107,10 +126,12 @@ public class FuseVolume implements Volume {
@Override
public void stop() {
try {
fuseMnt.cleanUp();
} catch (org.cryptomator.frontend.fuse.mount.CommandFailedException e) {
LOG.warn(e.getMessage());
if (extraDirCreated) {
try {
Files.delete(mountPath);
} catch (IOException e) {
LOG.warn("Could not delete mounting directory:" + e.getMessage());
}
}
}

View File

@@ -2,12 +2,14 @@ package org.cryptomator.ui.model;
import org.cryptomator.cryptofs.CryptoFileSystem;
import java.io.IOException;
/**
* Takes a Volume and usess it to mount an unlocked vault
*/
public interface Volume {
void prepare(CryptoFileSystem fs);
void prepare(CryptoFileSystem fs) throws IOException;
void mount() throws CommandFailedException;