mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-19 06:32:12 +00:00
adjusted in-memory filesystem to comply with API (return files/folders when requested, even though the oposite kind exists for the given name)
This commit is contained in:
+6
-3
@@ -16,6 +16,7 @@ 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;
|
||||
@@ -45,10 +46,12 @@ class InMemoryFile extends InMemoryNode implements File {
|
||||
writeLock.lock();
|
||||
final InMemoryFolder parent = parent().get();
|
||||
parent.children.compute(this.name(), (k, v) -> {
|
||||
if (v != null && v != this) {
|
||||
throw new IllegalStateException("More than one representation of same file");
|
||||
if (v == null || v == this) {
|
||||
this.lastModified = Instant.now();
|
||||
return this;
|
||||
} else {
|
||||
throw new UncheckedIOException(new FileExistsException(k));
|
||||
}
|
||||
return this;
|
||||
});
|
||||
return new InMemoryWritableFile(this::setLastModified, this::getContent, this::setContent, this::delete, writeLock);
|
||||
}
|
||||
|
||||
+7
-18
@@ -9,7 +9,6 @@
|
||||
package org.cryptomator.filesystem.inmem;
|
||||
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -36,31 +35,21 @@ class InMemoryFolder extends InMemoryNode implements Folder {
|
||||
|
||||
@Override
|
||||
public InMemoryFile file(String name) {
|
||||
InMemoryNode node = children.get(name);
|
||||
if (node == null) {
|
||||
node = volatileChildren.computeIfAbsent(name, (k) -> {
|
||||
return new InMemoryFile(this, name, Instant.MIN);
|
||||
});
|
||||
}
|
||||
final InMemoryNode node = children.get(name);
|
||||
if (node instanceof InMemoryFile) {
|
||||
return (InMemoryFile) node;
|
||||
} else {
|
||||
throw new UncheckedIOException(new FileAlreadyExistsException(name + " exists, but is not a file."));
|
||||
return new InMemoryFile(this, name, Instant.MIN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InMemoryFolder folder(String name) {
|
||||
InMemoryNode node = children.get(name);
|
||||
if (node == null) {
|
||||
node = volatileChildren.computeIfAbsent(name, (k) -> {
|
||||
return new InMemoryFolder(this, name, Instant.MIN);
|
||||
});
|
||||
}
|
||||
final InMemoryNode node = children.get(name);
|
||||
if (node instanceof InMemoryFolder) {
|
||||
return (InMemoryFolder) node;
|
||||
} else {
|
||||
throw new UncheckedIOException(new FileAlreadyExistsException(name + " exists, but is not a folder."));
|
||||
return new InMemoryFolder(this, name, Instant.MIN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +75,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
|
||||
@@ -112,7 +101,7 @@ class InMemoryFolder extends InMemoryNode implements Folder {
|
||||
subFolder.delete();
|
||||
}
|
||||
}
|
||||
assert !this.exists();
|
||||
assert!this.exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user