Sebastian Stenzel il y a 9 ans
Parent
commit
d397f59565

+ 2 - 1
main/filesystem-api/src/main/java/org/cryptomator/filesystem/delegating/DelegatingFolder.java

@@ -13,6 +13,7 @@ import java.util.Optional;
 import java.util.stream.Stream;
 
 import org.cryptomator.common.WeakValuedCache;
+import org.cryptomator.common.streams.AutoClosingStream;
 import org.cryptomator.filesystem.File;
 import org.cryptomator.filesystem.Folder;
 import org.cryptomator.filesystem.Node;
@@ -35,7 +36,7 @@ public abstract class DelegatingFolder<D extends DelegatingFolder<D, F>, F exten
 
 	@Override
 	public Stream<? extends Node> children() throws UncheckedIOException {
-		return Stream.concat(folders(), files());
+		return AutoClosingStream.from(Stream.concat(folders(), files()));
 	}
 
 	@Override

+ 2 - 1
main/filesystem-crypto/src/main/java/org/cryptomator/filesystem/crypto/CryptoFolder.java

@@ -23,6 +23,7 @@ import java.util.stream.Stream;
 import org.apache.commons.lang3.StringUtils;
 import org.cryptomator.common.LazyInitializer;
 import org.cryptomator.common.WeakValuedCache;
+import org.cryptomator.common.streams.AutoClosingStream;
 import org.cryptomator.crypto.engine.Cryptor;
 import org.cryptomator.filesystem.Deleter;
 import org.cryptomator.filesystem.File;
@@ -74,7 +75,7 @@ class CryptoFolder extends CryptoNode implements Folder {
 
 	@Override
 	public Stream<? extends Node> children() {
-		return Stream.concat(files(), folders());
+		return AutoClosingStream.from(Stream.concat(files(), folders()));
 	}
 
 	@Override

+ 12 - 4
main/frontend-webdav/src/main/java/org/cryptomator/frontend/webdav/jackrabbitservlet/DavFolder.java

@@ -32,6 +32,7 @@ import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.ResourceType;
+import org.cryptomator.common.streams.AutoClosingStream;
 import org.cryptomator.filesystem.Folder;
 import org.cryptomator.filesystem.Node;
 import org.cryptomator.filesystem.WritableFile;
@@ -90,7 +91,8 @@ class DavFolder extends DavNode<FolderLocator> {
 	public DavResourceIterator getMembers() {
 		final Stream<DavFolder> folders = node.folders().map(this::folderToDavFolder);
 		final Stream<DavFile> files = node.files().map(this::fileToDavFile);
-		return new DavResourceIteratorImpl(Stream.concat(folders, files).collect(Collectors.toList()));
+		final Stream<DavResource> members = AutoClosingStream.from(Stream.concat(folders, files));
+		return new DavResourceIteratorImpl(members.collect(Collectors.toList()));
 	}
 
 	private DavFolder folderToDavFolder(FolderLocator memberFolder) {
@@ -115,9 +117,15 @@ class DavFolder extends DavNode<FolderLocator> {
 	 *             Error 404 if no child with the given name exists
 	 */
 	private Node getMemberNode(String name) throws DavException {
-		return node.children().filter(c -> c.name().equals(name)).findAny().orElseThrow(() -> {
-			return new DavException(DavServletResponse.SC_NOT_FOUND, "No such file or directory: " + node.getResourcePath() + name);
-		});
+		Node file = node.file(name);
+		Node folder = node.folder(name);
+		if (file.exists()) {
+			return file;
+		} else if (folder.exists()) {
+			return folder;
+		} else {
+			throw new DavException(DavServletResponse.SC_NOT_FOUND, "No such file or directory: " + node.getResourcePath() + name);
+		}
 	}
 
 	@Override