- bugfix: slow webdav on windows (http://support.microsoft.com/kb/2445570)

- bugfix: windows mount on non-german installations
- bugfix: system-dependent implementation of mount commands now done in specific strategy. no linux-specific URI outside of mount package, thus working on OS X again and simplified windows code
- change: now using ipv6
This commit is contained in:
Sebastian Stenzel 2014-12-15 23:46:06 +01:00
parent ac4f10ce93
commit 8c2fe14e41
13 changed files with 42 additions and 88 deletions

View File

@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
public final class WebDAVServer {
private static final Logger LOG = LoggerFactory.getLogger(WebDAVServer.class);
private static final String LOCALHOST = "127.0.0.1";
private static final String LOCALHOST = "::1";
private static final int MAX_PENDING_REQUESTS = 200;
private static final int MAX_THREADS = 200;
private static final int MIN_THREADS = 4;

View File

@ -2,7 +2,6 @@ package org.cryptomator.ui.model;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
@ -14,9 +13,9 @@ import org.cryptomator.crypto.SamplingDecorator;
import org.cryptomator.crypto.aes256.Aes256Cryptor;
import org.cryptomator.ui.MainApplication;
import org.cryptomator.ui.util.MasterKeyFilter;
import org.cryptomator.ui.util.webdav.CommandFailedException;
import org.cryptomator.ui.util.webdav.WebDavMount;
import org.cryptomator.ui.util.webdav.WebDavMounter;
import org.cryptomator.ui.util.mount.CommandFailedException;
import org.cryptomator.ui.util.mount.WebDavMount;
import org.cryptomator.ui.util.mount.WebDavMounter;
import org.cryptomator.webdav.WebDAVServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -70,8 +69,7 @@ public class Directory implements Serializable {
public boolean mount() {
try {
URI shareUri = URI.create(String.format("dav://localhost:%d", server.getPort()));
webDavMount = WebDavMounter.mount(shareUri);
webDavMount = WebDavMounter.mount(server.getPort());
return true;
} catch (CommandFailedException e) {
LOG.warn("mount failed", e);

View File

@ -14,7 +14,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.cryptomator.ui.util.webdav.CommandFailedException;
import org.cryptomator.ui.util.mount.CommandFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -15,7 +15,7 @@ import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
import java.io.IOException;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.ui.util.webdav.CommandFailedException;
import org.cryptomator.ui.util.mount.CommandFailedException;
/**
* <p>

View File

@ -11,7 +11,7 @@ package org.cryptomator.ui.util.command;
import java.util.HashMap;
import java.util.Map;
import org.cryptomator.ui.util.webdav.CommandFailedException;
import org.cryptomator.ui.util.mount.CommandFailedException;
public final class Script {

View File

@ -7,7 +7,7 @@
* Sebastian Stenzel - initial API and implementation
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
package org.cryptomator.ui.util.mount;
public class CommandFailedException extends Exception {

View File

@ -6,9 +6,7 @@
* Contributors:
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
import java.net.URI;
package org.cryptomator.ui.util.mount;
/**
* A WebDavMounter acting as fallback if no other mounter works.
@ -23,7 +21,7 @@ final class FallbackWebDavMounter implements WebDavMounterStrategy {
}
@Override
public WebDavMount mount(URI uri) {
public WebDavMount mount(int localPort) {
displayMountInstructions();
return new WebDavMount() {
@Override

View File

@ -7,9 +7,7 @@
* Sebastian Stenzel - initial API and implementation
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
import java.net.URI;
package org.cryptomator.ui.util.mount;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.ui.util.command.Script;
@ -32,16 +30,16 @@ final class LinuxGvfsWebDavMounter implements WebDavMounterStrategy {
}
@Override
public WebDavMount mount(final URI uri) throws CommandFailedException {
public WebDavMount mount(int localPort) throws CommandFailedException {
final Script mountScript = Script.fromLines(
"set -x",
"gvfs-mount \"$URI\"",
"gvfs-mount \"dav://[::1]:$PORT\"",
"xdg-open \"$URI\"")
.addEnv("URI", uri.toString());
.addEnv("PORT", String.valueOf(localPort));
final Script unmountScript = Script.fromLines(
"set -x",
"gvfs-mount -u \"$URI\"")
.addEnv("URI", uri.toString());
"gvfs-mount -u \"dav://[::1]:$PORT\"")
.addEnv("URI", String.valueOf(localPort));
mountScript.execute().assertOk();
return new WebDavMount() {
@Override

View File

@ -4,12 +4,10 @@
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
* Sebastian Stenzel - initial API and implementation, strategy fine tuning
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
import java.net.URI;
package org.cryptomator.ui.util.mount;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.ui.util.command.Script;
@ -22,18 +20,18 @@ final class MacOsXWebDavMounter implements WebDavMounterStrategy {
}
@Override
public WebDavMount mount(URI uri) throws CommandFailedException {
final String path = "/Volumes/Cryptomator" + uri.getPort();
public WebDavMount mount(int localPort) throws CommandFailedException {
final String path = "/Volumes/Cryptomator" + localPort;
final Script mountScript = Script.fromLines(
"set -x",
"mkdir \"$MOUNT_PATH\"",
"mount_webdav -S -v Cryptomator \"$URI\" \"$MOUNT_PATH\"",
"mount_webdav -S -v Cryptomator \"[::1]:$PORT\" \"$MOUNT_PATH\"",
"open \"$MOUNT_PATH\"")
.addEnv("URI", uri.toString())
.addEnv("PORT", String.valueOf(localPort))
.addEnv("MOUNT_PATH", path);
final Script unmountScript = Script.fromLines(
"set -x",
"unmount $MOUNT_PATH")
"umount $MOUNT_PATH")
.addEnv("MOUNT_PATH", path);
mountScript.execute().assertOk();
return new WebDavMount() {

View File

@ -6,7 +6,7 @@
* Contributors:
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
package org.cryptomator.ui.util.mount;
/**

View File

@ -7,9 +7,7 @@
* Sebastian Stenzel - initial API and implementation
* Markus Kreusch - Refactored to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
import java.net.URI;
package org.cryptomator.ui.util.mount;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -18,24 +16,19 @@ public final class WebDavMounter {
private static final Logger LOG = LoggerFactory.getLogger(WebDavMounter.class);
private static final WebDavMounterStrategy[] STRATEGIES = {
new WindowsWebDavMounter(),
new MacOsXWebDavMounter(),
new LinuxGvfsWebDavMounter()
};
private static final WebDavMounterStrategy[] STRATEGIES = {new WindowsWebDavMounter(), new MacOsXWebDavMounter(), new LinuxGvfsWebDavMounter()};
private static volatile WebDavMounterStrategy choosenStrategy;
/**
* Tries to mount a given webdav share.
*
* @param uri
* the {@link URI} of the webdav share
* @param localPort local TCP port of the webdav share
* @return a {@link WebDavMount} representing the mounted share
* @throws CommandFailedException if the mount operation fails
*/
public static WebDavMount mount(URI uri) throws CommandFailedException {
return chooseStrategy().mount(uri);
public static WebDavMount mount(int localPort) throws CommandFailedException {
return chooseStrategy().mount(localPort);
}
private static WebDavMounterStrategy chooseStrategy() {

View File

@ -5,10 +5,10 @@
*
* Contributors:
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
* Sebastian Stenzel - minor strategy fine tuning
******************************************************************************/
package org.cryptomator.ui.util.webdav;
package org.cryptomator.ui.util.mount;
import java.net.URI;
/**
* A strategy able to mount a webdav share and display it to the user.
@ -18,19 +18,17 @@ import java.net.URI;
interface WebDavMounterStrategy {
/**
* @return {@code false} if this {@code WebDavMounterStrategy} can not work
* on the local machine, {@code true} if it could work
* @return {@code false} if this {@code WebDavMounterStrategy} can not work on the local machine, {@code true} if it could work
*/
boolean shouldWork();
/**
* Tries to mount a given webdav share.
*
* @param uri
* the {@link URI} of the webdav share
* @param localPort local TCP port of the webdav share
* @return a {@link WebDavMount} representing the mounted share
* @throws CommandFailedException if the mount operation fails
*/
WebDavMount mount(URI uri) throws CommandFailedException;
WebDavMount mount(int localPort) throws CommandFailedException;
}

View File

@ -4,16 +4,13 @@
* See the LICENSE.txt file for more info.
*
* Contributors:
* Sebastian Stenzel - initial API and implementation
* Sebastian Stenzel - initial API and implementation, strategy fine tuning
* Markus Kreusch - Refactored WebDavMounter to use strategy pattern
******************************************************************************/
package org.cryptomator.ui.util.webdav;
package org.cryptomator.ui.util.mount;
import static java.lang.String.format;
import static org.cryptomator.ui.util.command.Script.fromLines;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -30,7 +27,7 @@ import org.cryptomator.ui.util.command.Script;
*/
final class WindowsWebDavMounter implements WebDavMounterStrategy {
private static final Pattern WIN_MOUNT_DRIVELETTER_PATTERN = Pattern.compile("Laufwerk\\s*([A-Z]:)\\s*ist");
private static final Pattern WIN_MOUNT_DRIVELETTER_PATTERN = Pattern.compile("\\s*([A-Z]:)\\s*");
@Override
public boolean shouldWork() {
@ -38,11 +35,11 @@ final class WindowsWebDavMounter implements WebDavMounterStrategy {
}
@Override
public WebDavMount mount(URI uri) throws CommandFailedException {
public WebDavMount mount(int localPort) throws CommandFailedException {
final Script mountScript = fromLines(
"net use * %URI% /persistent:no",
"net use * http://0--1.ipv6-literal.net:%PORT% /persistent:no",
"if %errorLevel% neq 0 exit %errorLevel%")
.addEnv("URI", toHttpUri(uri));
.addEnv("PORT", String.valueOf(localPort));
final CommandResult mountResult = mountScript.execute();
mountResult.assertOk();
final String driveLetter = getDriveLetter(mountResult.getOutput());
@ -67,30 +64,4 @@ final class WindowsWebDavMounter implements WebDavMounterStrategy {
}
}
private String toHttpUri(URI uri) {
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) {
return uri.toString();
} else if ("dav".equals(uri.getScheme())) {
return replaceScheme(uri, "http").toString();
} else if ("davs".equals(uri.getScheme())) {
return replaceScheme(uri, "https").toString();
} else {
throw new IllegalStateException(format("No webdav uri %s", uri));
}
}
private URI replaceScheme(URI uri, String scheme) {
try {
return new URI(scheme,
uri.getUserInfo(),
uri.getHost(),
uri.getPort(),
uri.getPath(),
uri.getQuery(),
uri.getFragment());
} catch (URISyntaxException e) {
throw new IllegalStateException("Building an URI with replaced scheme failed");
}
}
}