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:
Markus Kreusch
2016-01-16 00:47:13 +01:00
parent a7eb99f7d5
commit 51f5b6661f
3 changed files with 11 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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
}

View File

@@ -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,