Skip to content

Commit 208be66

Browse files
committed
Merge branch 'release/2.0.2'
2 parents 6f7bc87 + 522ddd5 commit 208be66

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.cryptomator</groupId>
55
<artifactId>webdav-nio-adapter</artifactId>
6-
<version>2.0.1</version>
6+
<version>2.0.2</version>
77
<name>WebDAV-NIO Adapter</name>
88
<description>Embedded Jetty serving a WebDAV servlet to access resources at a given NIO path.</description>
99
<url>https://github.com/cryptomator/webdav-nio-adapter</url>
@@ -28,7 +28,7 @@
2828
<junit.jupiter.version>5.9.2</junit.jupiter.version>
2929

3030
<!-- mvn plugin dependencies -->
31-
<dependency-check.version>8.1.0</dependency-check.version>
31+
<dependency-check.version>8.1.2</dependency-check.version>
3232
<jacoco.version>0.8.8</jacoco.version>
3333
<nexus-staging.version>1.6.8</nexus-staging.version>
3434
<maven.deploy.version>3.1.0</maven.deploy.version>

src/main/java/org/cryptomator/frontend/webdav/DefaultServlet.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import javax.servlet.http.HttpServletRequest;
1414
import javax.servlet.http.HttpServletResponse;
1515
import java.io.IOException;
16-
import java.util.Collections;
1716
import java.util.Set;
17+
import java.util.concurrent.CopyOnWriteArraySet;
1818
import java.util.function.Predicate;
1919
import java.util.regex.Pattern;
2020

@@ -23,10 +23,10 @@ class DefaultServlet extends HttpServlet implements ContextPathRegistry {
2323
private static final String METHOD_PROPFIND = "PROPFIND";
2424
private static final int TARPIT_DELAY_MS = 5000;
2525
private static final Pattern PATH_SEP_PATTERN = Pattern.compile("/");
26-
private final Set<String> synchronizedContextPaths;
26+
private final Set<String> contextPaths;
2727

2828
public DefaultServlet(Set<String> contextPaths) {
29-
this.synchronizedContextPaths = Collections.synchronizedSet(contextPaths);
29+
this.contextPaths = new CopyOnWriteArraySet<>(contextPaths);
3030
}
3131

3232
@Override
@@ -44,12 +44,12 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
4444
}
4545

4646
switch (req.getMethod()) {
47-
case METHOD_PROPFIND:
48-
doPropfind(req, resp);
49-
break;
50-
default:
51-
super.service(req, resp);
52-
break;
47+
case METHOD_PROPFIND:
48+
doPropfind(req, resp);
49+
break;
50+
default:
51+
super.service(req, resp);
52+
break;
5353
}
5454
}
5555

@@ -79,24 +79,17 @@ protected void doPropfind(HttpServletRequest req, HttpServletResponse resp) thro
7979
}
8080

8181
private boolean isRequestedResourcePathPartOfValidContextPath(String requestedResourcePath) {
82-
//required for synchronized collections, see https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Collections.html#synchronizedSet(java.util.Set)
83-
synchronized (synchronizedContextPaths) {
84-
return synchronizedContextPaths.stream().anyMatch(cp -> isParentOrSamePath(cp, requestedResourcePath));
85-
}
82+
return contextPaths.stream().anyMatch(cp -> isParentOrSamePath(cp, requestedResourcePath));
8683
}
8784

8885
@Override
8986
public boolean add(String contextPath) {
90-
synchronized (synchronizedContextPaths) {
91-
return synchronizedContextPaths.add(contextPath);
92-
}
87+
return contextPaths.add(contextPath);
9388
}
9489

9590
@Override
9691
public boolean remove(String contextPath) {
97-
synchronized (synchronizedContextPaths) {
98-
return synchronizedContextPaths.remove(contextPath);
99-
}
92+
return contextPaths.remove(contextPath);
10093
}
10194

10295
private boolean isParentOrSamePath(String path, String potentialParent) {

src/main/java/org/cryptomator/frontend/webdav/mount/WindowsMounter.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public MountBuilder setMountpoint(Path mountPoint) {
8383
public MountBuilder setLoopbackHostName(String hostName) {
8484
this.hostName = hostName;
8585
try {
86-
Path.of("\\\\"+hostName+"\\share");
87-
new URL("http",hostName,80,"/");
86+
Path.of("\\\\" + hostName + "\\share");
87+
new URL("http", hostName, 80, "/");
8888
} catch (MalformedURLException | InvalidPathException e) {
89-
throw new IllegalArgumentException("hostName \""+hostName+"\" does not satifsfy OS restrictions.",e);
89+
throw new IllegalArgumentException("hostName \"" + hostName + "\" does not satifsfy OS restrictions.", e);
9090
}
9191
return this;
9292
}
@@ -109,8 +109,8 @@ protected Mount mount(WebDavServerHandle serverHandle, WebDavServletController s
109109
tuneProxyConfigSilently(uri);
110110
String mountPoint = driveLetter == null //
111111
? SYSTEM_CHOSEN_MOUNTPOINT // MOUNT_TO_SYSTEM_CHOSEN_PATH
112-
: driveLetter.toString(); // MOUNT_AS_DRIVE_LETTER
113-
String uncPath = "\\\\" + (hostName == null? uri.getHost() : hostName) + "@" + uri.getPort() + uri.getRawPath().replace('/', '\\');
112+
: driveLetter.toString().substring(0, 2); // MOUNT_AS_DRIVE_LETTER
113+
String uncPath = "\\\\" + (hostName == null ? uri.getHost() : hostName) + "@" + uri.getPort() + uri.getRawPath().replace('/', '\\');
114114
ProcessBuilder mount = new ProcessBuilder("net", "use", mountPoint, uncPath, "/persistent:no");
115115
Process mountProcess = mount.start();
116116
ProcessUtil.waitFor(mountProcess, 30, TimeUnit.SECONDS);
@@ -125,7 +125,7 @@ protected Mount mount(WebDavServerHandle serverHandle, WebDavServletController s
125125
}
126126

127127
LOG.debug("Mounted {} on drive {}", uncPath, actualMountpoint);
128-
return new MountImpl(serverHandle, servlet, actualMountpoint);
128+
return new MountImpl(serverHandle, servlet, actualMountpoint, uncPath);
129129
} catch (IOException | TimeoutException e) {
130130
throw new MountFailedException(e);
131131
}
@@ -167,7 +167,7 @@ private static void tuneProxyConfigSilently(URI uri) {
167167

168168
/**
169169
* @param uri The URI for which to tune the registry settings
170-
* @throws IOException If registry access fails
170+
* @throws IOException If registry access fails
171171
* @throws TimeoutException If registry access does not finish in time
172172
* @deprecated TODO overheadhunter: check if this is really necessary.
173173
*/
@@ -205,13 +205,15 @@ private static class MountImpl extends AbstractMount {
205205
private final ProcessBuilder forcedUnmountCommand;
206206

207207
private final Path mountpoint;
208+
private final String uncPath;
208209
private final AtomicBoolean isUnmounted;
209210

210-
public MountImpl(WebDavServerHandle serverHandle, WebDavServletController servlet, String driveLetter) {
211+
public MountImpl(WebDavServerHandle serverHandle, WebDavServletController servlet, String driveLetter, String uncPath) {
211212
super(serverHandle, servlet);
212213
this.unmountCommand = new ProcessBuilder("net", "use", driveLetter, "/delete", "/no");
213214
this.forcedUnmountCommand = new ProcessBuilder("net", "use", driveLetter, "/delete", "/yes");
214215
this.mountpoint = Path.of(driveLetter + "\\");
216+
this.uncPath = uncPath;
215217
this.isUnmounted = new AtomicBoolean(false);
216218
}
217219

@@ -267,9 +269,6 @@ private synchronized void unmount(ProcessBuilder command) throws UnmountFailedEx
267269
@SuppressWarnings("resource")
268270
private boolean isUnmounted() {
269271
try {
270-
var uri = servlet.getServletRootUri();
271-
String uncPath = "\\\\" + uri.getHost() + "@" + uri.getPort() + uri.getRawPath().replace('/', '\\');
272-
273272
ProcessBuilder determineMP = new ProcessBuilder("net", "use");
274273
Process determineMPProcess = ProcessUtil.startAndWaitFor(determineMP, 5, TimeUnit.SECONDS);
275274
ProcessUtil.assertExitValue(determineMPProcess, 0);

src/test/java/org/cryptomator/frontend/webdav/MirroringTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ public static void main(String[] args) throws MountFailedException, IOException
5151
if (mountProvider.hasCapability(MountCapability.VOLUME_ID)) {
5252
mountBuilder.setVolumeId("testMount");
5353
}
54-
54+
if (mountProvider.hasCapability(MountCapability.VOLUME_NAME)) {
55+
mountBuilder.setVolumeName("testName");
56+
}
57+
if (mountProvider.hasCapability(MountCapability.MOUNT_AS_DRIVE_LETTER)) {
58+
mountBuilder.setMountpoint(Path.of("X://"));
59+
}
60+
//if (mountProvider.hasCapability(MountCapability.LOOPBACK_HOST_NAME)) {
61+
// mountBuilder.setLoopbackHostName("cryptomator-vault");
62+
//}
5563
try (var mount = mountBuilder.mount()) {
5664
LOG.info("Mounted successfully to: {}", mount.getMountpoint().uri());
5765
LOG.info("Enter anything to unmount...");

0 commit comments

Comments
 (0)