Fixed CryptoFileSystem

* avoid creation of a file and folder with equal names
This commit is contained in:
Markus Kreusch
2016-02-14 23:07:55 +01:00
parent 932e26f6a6
commit 8cdb6d0eab
4 changed files with 31 additions and 5 deletions
@@ -11,6 +11,9 @@ package org.cryptomator.filesystem.crypto;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.Optional;
import java.io.UncheckedIOException;
import java.nio.file.FileAlreadyExistsException;
import java.time.Instant;
import org.cryptomator.crypto.engine.Cryptor;
import org.cryptomator.filesystem.File;
@@ -38,6 +41,9 @@ public class CryptoFile extends CryptoNode implements File {
@Override
public WritableFile openWritable() {
if (parent.folder(name).exists()) {
throw new UncheckedIOException(new FileAlreadyExistsException(toString()));
}
return new CryptoWritableFile(cryptor.getFileContentCryptor(), forceGetPhysicalFile().openWritable());
}
@@ -16,6 +16,7 @@ import java.io.Reader;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.nio.channels.Channels;
import java.nio.file.FileAlreadyExistsException;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
@@ -152,6 +153,9 @@ class CryptoFolder extends CryptoNode implements Folder {
} else if (!newDirIdGiven) {
throw new IllegalStateException("Newly created folder, that didn't exist before, already had an directoryId.");
}
if (parent.file(name).exists()) {
throw new UncheckedIOException(new FileAlreadyExistsException(toString()));
}
try (Writer writer = Channels.newWriter(dirFile.openWritable(), UTF_8.newEncoder(), -1)) {
writer.write(directoryId.get());
} catch (IOException e) {