mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-04 15:18:09 +00:00
several WebDAV compliance fixes
This commit is contained in:
+9
-6
@@ -11,12 +11,12 @@ package org.cryptomator.filesystem.inmem;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
|
||||
import org.apache.commons.io.FileExistsException;
|
||||
import org.cryptomator.filesystem.File;
|
||||
import org.cryptomator.filesystem.ReadableFile;
|
||||
import org.cryptomator.filesystem.WritableFile;
|
||||
@@ -53,12 +53,15 @@ class InMemoryFile extends InMemoryNode implements File {
|
||||
writeLock.lock();
|
||||
final InMemoryFolder parent = parent().get();
|
||||
parent.existingChildren.compute(this.name(), (k, v) -> {
|
||||
if (v == null || v == this) {
|
||||
this.lastModified = Instant.now();
|
||||
this.creationTime = Instant.now();
|
||||
return this;
|
||||
if (v != null && v != this) {
|
||||
// other file or folder with same name already exists.
|
||||
throw new UncheckedIOException(new FileAlreadyExistsException(k));
|
||||
} else {
|
||||
throw new UncheckedIOException(new FileExistsException(k));
|
||||
if (v == null) {
|
||||
this.creationTime = Instant.now();
|
||||
}
|
||||
this.lastModified = Instant.now();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
return new InMemoryWritableFile(this::setLastModified, this::setCreationTime, this::getContent, this::setContent, this::delete, writeLock);
|
||||
|
||||
+14
-8
@@ -15,7 +15,7 @@ import java.io.UncheckedIOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.io.FileExistsException;
|
||||
@@ -24,7 +24,7 @@ import org.cryptomator.filesystem.Folder;
|
||||
|
||||
class InMemoryFolder extends InMemoryNode implements Folder {
|
||||
|
||||
final Map<String, InMemoryNode> existingChildren = new TreeMap<>();
|
||||
final Map<String, InMemoryNode> existingChildren = new ConcurrentHashMap<>();
|
||||
|
||||
private final WeakValuedCache<String, InMemoryFolder> folders = WeakValuedCache.usingLoader(this::newFolder);
|
||||
private final WeakValuedCache<String, InMemoryFile> files = WeakValuedCache.usingLoader(this::newFile);
|
||||
@@ -67,11 +67,12 @@ class InMemoryFolder extends InMemoryNode implements Folder {
|
||||
}
|
||||
parent.create();
|
||||
parent.existingChildren.compute(name, (k, v) -> {
|
||||
if (v == null) {
|
||||
if (v != null) {
|
||||
// other file or folder with same name already exists.
|
||||
throw new UncheckedIOException(new FileExistsException(k));
|
||||
} else {
|
||||
this.lastModified = Instant.now();
|
||||
return this;
|
||||
} else {
|
||||
throw new UncheckedIOException(new FileExistsException(k));
|
||||
}
|
||||
});
|
||||
assert this.exists();
|
||||
@@ -83,11 +84,11 @@ class InMemoryFolder extends InMemoryNode implements Folder {
|
||||
if (target.exists()) {
|
||||
target.delete();
|
||||
}
|
||||
assert !target.exists();
|
||||
assert!target.exists();
|
||||
target.create();
|
||||
this.copyTo(target);
|
||||
this.delete();
|
||||
assert !this.exists();
|
||||
assert!this.exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,7 +110,12 @@ class InMemoryFolder extends InMemoryNode implements Folder {
|
||||
subFolder.delete();
|
||||
}
|
||||
}
|
||||
assert !this.exists();
|
||||
assert!this.exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreationTime(Instant instant) throws UncheckedIOException {
|
||||
creationTime = instant;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user