mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
allow to store custom mount flags in the vault settings (required for #802)
[ci skip]
This commit is contained in:
@@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@@ -44,6 +45,7 @@ public class VaultSettings {
|
||||
private final BooleanProperty usesIndividualMountPath = new SimpleBooleanProperty(DEFAULT_USES_INDIVIDUAL_MOUNTPATH);
|
||||
private final StringProperty individualMountPath = new SimpleStringProperty();
|
||||
private final BooleanProperty usesReadOnlyMode = new SimpleBooleanProperty(DEFAULT_USES_READONLY_MODE);
|
||||
private final ObjectProperty<List<String>> mountFlags = new SimpleObjectProperty<>(List.of());
|
||||
|
||||
public VaultSettings(String id) {
|
||||
this.id = Objects.requireNonNull(id);
|
||||
@@ -147,6 +149,10 @@ public class VaultSettings {
|
||||
return usesReadOnlyMode;
|
||||
}
|
||||
|
||||
public ObjectProperty<List<String>> mountFlags() {
|
||||
return mountFlags;
|
||||
}
|
||||
|
||||
/* Hashcode/Equals */
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
package org.cryptomator.common.settings;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class VaultSettingsJsonAdapter {
|
||||
|
||||
@@ -26,8 +29,10 @@ class VaultSettingsJsonAdapter {
|
||||
out.name("unlockAfterStartup").value(value.unlockAfterStartup().get());
|
||||
out.name("revealAfterMount").value(value.revealAfterMount().get());
|
||||
out.name("usesIndividualMountPath").value(value.usesIndividualMountPath().get());
|
||||
out.name("individualMountPath").value(value.individualMountPath().get()); //TODO: should this always be written? ( because it could contain metadata, which the user may not want to save!)
|
||||
out.name("individualMountPath").value(value.individualMountPath().get());
|
||||
out.name("usesReadOnlyMode").value(value.usesReadOnlyMode().get());
|
||||
out.name("mountFlags");
|
||||
writeMountFlags(out, value.mountFlags().get());
|
||||
out.endObject();
|
||||
}
|
||||
|
||||
@@ -41,6 +46,7 @@ class VaultSettingsJsonAdapter {
|
||||
boolean revealAfterMount = VaultSettings.DEFAULT_REAVEAL_AFTER_MOUNT;
|
||||
boolean usesIndividualMountPath = VaultSettings.DEFAULT_USES_INDIVIDUAL_MOUNTPATH;
|
||||
boolean usesReadOnlyMode = VaultSettings.DEFAULT_USES_READONLY_MODE;
|
||||
List<String> mountFlags = null;
|
||||
|
||||
in.beginObject();
|
||||
while (in.hasNext()) {
|
||||
@@ -73,6 +79,9 @@ class VaultSettingsJsonAdapter {
|
||||
case "usesReadOnlyMode":
|
||||
usesReadOnlyMode = in.nextBoolean();
|
||||
break;
|
||||
case "mountFlags":
|
||||
mountFlags = readMountFlags(in);
|
||||
break;
|
||||
default:
|
||||
LOG.warn("Unsupported vault setting found in JSON: " + name);
|
||||
in.skipValue();
|
||||
@@ -90,7 +99,26 @@ class VaultSettingsJsonAdapter {
|
||||
vaultSettings.usesIndividualMountPath().set(usesIndividualMountPath);
|
||||
vaultSettings.individualMountPath().set(individualMountPath);
|
||||
vaultSettings.usesReadOnlyMode().set(usesReadOnlyMode);
|
||||
vaultSettings.mountFlags().set(mountFlags);
|
||||
return vaultSettings;
|
||||
}
|
||||
|
||||
private List<String> readMountFlags(JsonReader in) throws IOException {
|
||||
List<String> result = new ArrayList<>();
|
||||
in.beginArray();
|
||||
while (!JsonToken.END_ARRAY.equals(in.peek())) {
|
||||
result.add(in.nextString());
|
||||
}
|
||||
in.endArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void writeMountFlags(JsonWriter out, List<String> flags) throws IOException {
|
||||
out.beginArray();
|
||||
for (String flag : flags) {
|
||||
out.value(flag);
|
||||
}
|
||||
out.endArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,17 @@
|
||||
package org.cryptomator.common.settings;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class VaultSettingsJsonAdapterTest {
|
||||
|
||||
@@ -19,7 +24,7 @@ public class VaultSettingsJsonAdapterTest {
|
||||
|
||||
@Test
|
||||
public void testDeserialize() throws IOException {
|
||||
String json = "{\"id\": \"foo\", \"path\": \"/foo/bar\", \"mountName\": \"test\", \"winDriveLetter\": \"X\", \"shouldBeIgnored\": true, \"individualMountPath\": \"/home/test/crypto\"}";
|
||||
String json = "{\"id\": \"foo\", \"path\": \"/foo/bar\", \"mountName\": \"test\", \"winDriveLetter\": \"X\", \"shouldBeIgnored\": true, \"individualMountPath\": \"/home/test/crypto\", \"mountFlags\":[\"--foo\", \"--bar\"]}";
|
||||
JsonReader jsonReader = new JsonReader(new StringReader(json));
|
||||
|
||||
VaultSettings vaultSettings = adapter.read(jsonReader);
|
||||
@@ -28,6 +33,27 @@ public class VaultSettingsJsonAdapterTest {
|
||||
Assertions.assertEquals("test", vaultSettings.mountName().get());
|
||||
Assertions.assertEquals("X", vaultSettings.winDriveLetter().get());
|
||||
Assertions.assertEquals("/home/test/crypto", vaultSettings.individualMountPath().get());
|
||||
MatcherAssert.assertThat(vaultSettings.mountFlags().get(), CoreMatchers.hasItems("--foo", "--bar"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialize() throws IOException {
|
||||
VaultSettings vaultSettings = new VaultSettings("test");
|
||||
vaultSettings.path().set(Paths.get("/foo/bar"));
|
||||
vaultSettings.mountName().set("mountyMcMountFace");
|
||||
vaultSettings.mountFlags().set(Arrays.asList("--foo", "--bar"));
|
||||
|
||||
StringWriter buf = new StringWriter();
|
||||
JsonWriter jsonWriter = new JsonWriter(buf);
|
||||
adapter.write(jsonWriter, vaultSettings);
|
||||
String result = buf.toString();
|
||||
|
||||
MatcherAssert.assertThat(result, CoreMatchers.containsString("\"id\":\"test\""));
|
||||
MatcherAssert.assertThat(result, CoreMatchers.containsString("\"path\":\"/foo/bar\""));
|
||||
MatcherAssert.assertThat(result, CoreMatchers.containsString("\"mountName\":\"mountyMcMountFace\""));
|
||||
MatcherAssert.assertThat(result, CoreMatchers.containsString("\"mountFlags\":[\"--foo\",\"--bar\"]"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<cryptomator.cryptolib.version>1.2.1</cryptomator.cryptolib.version>
|
||||
<cryptomator.cryptofs.version>1.8.5</cryptomator.cryptofs.version>
|
||||
<cryptomator.jni.version>2.0.0</cryptomator.jni.version>
|
||||
<cryptomator.fuse.version>1.1.3</cryptomator.fuse.version>
|
||||
<cryptomator.fuse.version>1.2.0-SNAPSHOT</cryptomator.fuse.version>
|
||||
<cryptomator.dokany.version>1.1.8</cryptomator.dokany.version>
|
||||
<cryptomator.webdav.version>1.0.10</cryptomator.webdav.version>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.cryptomator.frontend.fuse.mount.EnvironmentVariables;
|
||||
import org.cryptomator.frontend.fuse.mount.FuseMountFactory;
|
||||
import org.cryptomator.frontend.fuse.mount.FuseNotSupportedException;
|
||||
import org.cryptomator.frontend.fuse.mount.Mount;
|
||||
import org.cryptomator.frontend.fuse.mount.Mounter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -20,6 +21,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.NotDirectoryException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FuseVolume implements Volume {
|
||||
@@ -96,16 +98,26 @@ public class FuseVolume implements Volume {
|
||||
|
||||
private void mount(Path root) throws VolumeException {
|
||||
try {
|
||||
Mounter mounter = FuseMountFactory.getMounter();
|
||||
EnvironmentVariables envVars = EnvironmentVariables.create() //
|
||||
.withMountName(vaultSettings.mountName().getValue()) //
|
||||
.withMountPath(mountPoint) //
|
||||
.withFlags(mountFlags(mounter))
|
||||
.withMountPoint(mountPoint) //
|
||||
.build();
|
||||
this.fuseMnt = FuseMountFactory.getMounter().mount(root, envVars);
|
||||
this.fuseMnt = mounter.mount(root, envVars);
|
||||
} catch (CommandFailedException e) {
|
||||
throw new VolumeException("Unable to mount Filesystem", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] mountFlags(Mounter mounter) {
|
||||
List<String> mountFlags = vaultSettings.mountFlags().get();
|
||||
if (mountFlags.isEmpty()) {
|
||||
return mounter.defaultMountFlags();
|
||||
} else {
|
||||
return mountFlags.toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reveal() throws VolumeException {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user