mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-21 04:01:27 +00:00
Adjusted fix for issue in CryptoFileSystem when deleting a file
* CryptoWritableFile now only invokes writeTaks.get if not already closed * CryptoWritableFile now cancels writeTask before delete
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.cryptomator.filesystem.crypto;
|
||||
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@@ -25,7 +27,7 @@ class CiphertextWriter implements Callable<Void> {
|
||||
file.write(ciphertext);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new UncheckedIOException(new InterruptedIOException("Task interrupted while waiting for ciphertext"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,13 @@ import org.cryptomator.crypto.engine.FileContentCryptor;
|
||||
import org.cryptomator.crypto.engine.FileContentEncryptor;
|
||||
import org.cryptomator.filesystem.WritableFile;
|
||||
import org.cryptomator.io.ByteBuffers;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class CryptoWritableFile implements WritableFile {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CryptoWritableFile.class);
|
||||
|
||||
final WritableFile file;
|
||||
private final ExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
private final FileContentEncryptor encryptor;
|
||||
@@ -82,6 +86,7 @@ class CryptoWritableFile implements WritableFile {
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
writeTask.cancel(true);
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@@ -107,9 +112,9 @@ class CryptoWritableFile implements WritableFile {
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
encryptor.append(FileContentCryptor.EOF);
|
||||
writeTask.get();
|
||||
if (file.isOpen()) {
|
||||
encryptor.append(FileContentCryptor.EOF);
|
||||
writeTask.get();
|
||||
writeHeader();
|
||||
// TODO append padding
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class InMemoryWritableFile implements WritableFile {
|
||||
private final Consumer<Void> deleter;
|
||||
private final WriteLock writeLock;
|
||||
|
||||
private boolean open;
|
||||
private boolean open = true;
|
||||
private int position = 0;
|
||||
|
||||
public InMemoryWritableFile(Consumer<Instant> lastModifiedSetter, Consumer<Instant> creationTimeSetter, Supplier<ByteBuffer> contentGetter, Consumer<ByteBuffer> contentSetter, Consumer<Void> deleter,
|
||||
|
||||
Reference in New Issue
Block a user