mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 08:41:28 +00:00
- fixed invalid path for windows logfiles
- yet another attempt to improve (i don't even dare to say fix) #41
This commit is contained in:
@@ -2,11 +2,11 @@ package org.cryptomator.ui.logging;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.apache.logging.log4j.core.Filter;
|
||||
@@ -30,6 +30,7 @@ public class ConfigurableFileAppender extends AbstractOutputStreamAppender<FileM
|
||||
private static final long serialVersionUID = -6548221568069606389L;
|
||||
private static final int DEFAULT_BUFFER_SIZE = 8192;
|
||||
private static final String DEFAULT_FILE_NAME = "cryptomator.log";
|
||||
private static final Pattern DRIVE_LETTER_WITH_PRECEEDING_SLASH = Pattern.compile("^/[A-Z]:", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
protected ConfigurableFileAppender(String name, Layout<? extends Serializable> layout, Filter filter, FileManager manager) {
|
||||
super(name, layout, filter, true, true, manager);
|
||||
@@ -66,8 +67,12 @@ public class ConfigurableFileAppender extends AbstractOutputStreamAppender<FileM
|
||||
} else {
|
||||
// relative Path:
|
||||
try {
|
||||
final URI jarFileLocation = ConfigurableFileAppender.class.getProtectionDomain().getCodeSource().getLocation().toURI();
|
||||
final Path workingDir = FileSystems.getDefault().getPath(jarFileLocation.getPath()).getParent();
|
||||
String jarFileLocation = ConfigurableFileAppender.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
|
||||
if (SystemUtils.IS_OS_WINDOWS && DRIVE_LETTER_WITH_PRECEEDING_SLASH.matcher(jarFileLocation).find()) {
|
||||
// on windows we need to remove a preceeding slash from "/C:/foo/bar":
|
||||
jarFileLocation = jarFileLocation.substring(1);
|
||||
}
|
||||
final Path workingDir = FileSystems.getDefault().getPath(jarFileLocation).getParent();
|
||||
filePath = workingDir.resolve(fileName);
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.error("Unable to resolve working directory ", e);
|
||||
|
||||
@@ -140,7 +140,7 @@ public class SingleInstanceManager {
|
||||
if (key.isAcceptable()) {
|
||||
final SocketChannel accepted = channel.accept();
|
||||
if (accepted != null) {
|
||||
LOG.info("accepted incoming connection");
|
||||
LOG.debug("accepted incoming connection");
|
||||
accepted.configureBlocking(false);
|
||||
accepted.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class SingleInstanceManager {
|
||||
if (!state.write.hasRemaining()) {
|
||||
state.write = null;
|
||||
}
|
||||
LOG.debug("wrote welcome. switching to read only.");
|
||||
LOG.trace("wrote welcome. switching to read only.");
|
||||
key.interestOps(SelectionKey.OP_READ);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class SingleInstanceManager {
|
||||
try {
|
||||
channel = SocketChannel.open();
|
||||
channel.configureBlocking(false);
|
||||
LOG.info("connecting to instance {}", port.get());
|
||||
LOG.debug("connecting to instance {}", port.get());
|
||||
channel.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port.get()));
|
||||
|
||||
SocketChannel fChannel = channel;
|
||||
@@ -255,7 +255,7 @@ public class SingleInstanceManager {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
LOG.info("connected to instance {}", port.get());
|
||||
LOG.debug("connected to instance {}", port.get());
|
||||
|
||||
final byte[] bytes = applicationKey.getBytes();
|
||||
ByteBuffer buf = ByteBuffer.allocate(bytes.length);
|
||||
@@ -313,7 +313,7 @@ public class SingleInstanceManager {
|
||||
|
||||
final int port = ((InetSocketAddress) channel.getLocalAddress()).getPort();
|
||||
Preferences.userNodeForPackage(Cryptomator.class).putInt(applicationKey, port);
|
||||
LOG.info("InstanceManager bound to port {}", port);
|
||||
LOG.debug("InstanceManager bound to port {}", port);
|
||||
|
||||
Selector selector = Selector.open();
|
||||
channel.register(selector, SelectionKey.OP_ACCEPT);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.cryptomator.ui.util.command.Script;
|
||||
final class WindowsWebDavMounter implements WebDavMounterStrategy {
|
||||
|
||||
private static final Pattern WIN_MOUNT_DRIVELETTER_PATTERN = Pattern.compile("\\s*([A-Z]:)\\s*");
|
||||
private static final int MAX_MOUNT_ATTEMPTS = 10;
|
||||
private static final int MAX_MOUNT_ATTEMPTS = 12;
|
||||
|
||||
@Override
|
||||
public boolean shouldWork() {
|
||||
@@ -42,9 +42,11 @@ final class WindowsWebDavMounter implements WebDavMounterStrategy {
|
||||
@Override
|
||||
public void warmUp(int serverPort) {
|
||||
try {
|
||||
final Script proxyBypassCmd = fromLines("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v \"ProxyOverride\" /d \"<local>;0--1.ipv6-literal.net\" /f");
|
||||
final Script proxyBypassCmd = fromLines("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v \"ProxyOverride\" /d \"<local>;0--1.ipv6-literal.net;0--1.ipv6-literal.net:%PORT%\" /f");
|
||||
proxyBypassCmd.addEnv("PORT", String.valueOf(serverPort));
|
||||
proxyBypassCmd.execute();
|
||||
final Script mountCmd = fromLines("net use * http://0--1.ipv6-literal.net:" + serverPort + "/bill-gates-mom-uses-goto /persistent:no");
|
||||
final Script mountCmd = fromLines("net use * http://0--1.ipv6-literal.net:%PORT%/bill-gates-mom-uses-goto /persistent:no");
|
||||
mountCmd.addEnv("PORT", String.valueOf(serverPort));
|
||||
mountCmd.execute();
|
||||
} catch (CommandFailedException e) {
|
||||
// will most certainly throw an exception, because this is a fake WebDav path. But now windows has some DNS things cached :)
|
||||
@@ -53,13 +55,16 @@ final class WindowsWebDavMounter implements WebDavMounterStrategy {
|
||||
|
||||
@Override
|
||||
public WebDavMount mount(URI uri, String name) throws CommandFailedException {
|
||||
final Script proxyBypassCmd = fromLines("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v \"ProxyOverride\" /d \"<local>;0--1.ipv6-literal.net;0--1.ipv6-literal.net:%PORT%\" /f");
|
||||
proxyBypassCmd.addEnv("PORT", String.valueOf(uri.getPort()));
|
||||
final Script mountScript = fromLines("net use * http://0--1.ipv6-literal.net:%PORT%%DAV_PATH% /persistent:no");
|
||||
mountScript.addEnv("PORT", String.valueOf(uri.getPort())).addEnv("DAV_PATH", uri.getRawPath());
|
||||
String driveLetter = null;
|
||||
// The ugliness of the following 20 lines is solely windows' fault. Deal with it.
|
||||
for (int i = 0; i < MAX_MOUNT_ATTEMPTS; i++) {
|
||||
try {
|
||||
final CommandResult mountResult = mountScript.execute(10, TimeUnit.SECONDS);
|
||||
proxyBypassCmd.execute();
|
||||
final CommandResult mountResult = mountScript.execute(5, TimeUnit.SECONDS);
|
||||
driveLetter = getDriveLetter(mountResult.getStdOut());
|
||||
break;
|
||||
} catch (CommandFailedException ex) {
|
||||
@@ -67,8 +72,8 @@ final class WindowsWebDavMounter implements WebDavMounterStrategy {
|
||||
throw ex;
|
||||
} else {
|
||||
try {
|
||||
// retry after 2s
|
||||
Thread.sleep(2000);
|
||||
// retry after 2.5s
|
||||
Thread.sleep(2500);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user