mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-10-01 12:15:32 +00:00
Fixed CryptoFileSystem
* avoid creation of a file and folder with equal names
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user